Git Product home page Git Product logo

pathspec-ruby's Introduction

pathspec-ruby

Gem Version Ruby Maintainability

man Page as HTML

Supported Rubies:

  • 3.1 (Stable, Tested)
  • 3.2 (Stable, Tested)
  • 3.3 (Stable, Tested)

Match Path Specifications, such as .gitignore, in Ruby!

Follows .gitignore syntax defined on gitscm

.gitignore functionality ported from Python pathspec by @cpburnz

Build/Install from Rubygems

gem install pathspec

CLI Usage

➜ cat .gitignore
*.swp
/coverage/
➜ bundle exec pathspec-rb specs_match "coverage/foo"
/coverage/
➜ bundle exec pathspec-rb specs_match "file.swp"
*.swp
➜ bundle exec pathspec-rb match "file.swp"echo $?
0
➜ ls
Gemfile      Gemfile.lock coverage     file.swp     source.rb
➜ bundle exec pathspec-rb tree .
./coverage
./coverage/index.html
./file.swp

Usage

require 'pathspec'

# Create a .gitignore-style Pathspec by giving it newline separated gitignore
# lines, an array of gitignore lines, or any other enumable object that will
# give strings matching the .gitignore-style (File, etc.)
gitignore = PathSpec.from_filename('spec/files/gitignore_readme')

# Our .gitignore in this example contains:
# !**/important.txt
# abc/**

# true, matches "abc/**"
gitignore.match 'abc/def.rb'
# CLI equivalent: pathspec.rb -f spec/files/gitignore_readme match 'abc/def.rb'

# false, because it has been negated using the line "!**/important.txt"
gitignore.match 'abc/important.txt'
# CLI equivalent: pathspec.rb -f spec/files/gitignore_readme match 'abc/important.txt'

# Give a path somewhere in the filesystem, and the Pathspec will return all
# matching files underneath.
# Returns ['/src/repo/abc/', '/src/repo/abc/123']
gitignore.match_tree '/src/repo'
# CLI equivalent: pathspec.rb -f spec/files/gitignore_readme tree /src/repo

# Give an enumerable of paths, and Pathspec will return the ones that match.
# Returns ['/abc/123', '/abc/']
gitignore.match_paths ['/abc/123', '/abc/important.txt', '/abc/']
# There is no CLI equivalent to this.

Example Usage in Gemspec

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "gemspec_pathspec_test/version"
require 'pathspec'

Gem::Specification.new do |spec|
  spec.name          = "gemspec_pathspec_test"
  spec.version       = GemspecPathspecTest::VERSION
  spec.authors       = ["Brandon High"]
  spec.email         = ["[email protected]"]

  spec.summary = "whatever"

  spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"

  ps = PathSpec.from_filename('.gitignore')
  spec.files         = Dir['lib/*.rb'].reject { |f| ps.match(f) }
  spec.bindir        = "exe"
  spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
  spec.require_paths = ["lib"]

  spec.add_development_dependency "bundler", "~> 2.0"
  spec.add_development_dependency "rake", "~> 10.0"
  spec.add_development_dependency "rspec", "~> 3.0"
end

Building/Installing from Source

git clone [email protected]:highb/pathspec-ruby.git
cd pathspec-ruby && bash ./build_from_source.sh

Contributing

Pull requests, bug reports, and feature requests welcome! 😄 I've tried to write exhaustive tests but who knows what cases I've missed.

Releasing

This is mainly a reminder to myself but the release process is:

  1. Make sure CI is passing
  2. Update the CHANGELOG with relevant changes to Gem consumers
  3. Update version in gemspec with correct SemVer bump for scope of changes
  4. Tag/release using GitHub UI and the Build & Push workflow should do the rest.

pathspec-ruby's People

Contributors

boogles avatar highb avatar incase avatar jcoleman avatar jdpace avatar ktdreyer avatar lelutin avatar martinandert avatar renovate[bot] avatar sumlare avatar tenderlove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pathspec-ruby's Issues

binary file pathspec-rb is missing a man page

Hi there!

I'm currently working on packaging your gem for debian, and I was warned by the debian linting utility, lintian, that there is no man page for the binary pathspec-rb.

It's always nice to have a documentation page that one can find with man $binary to get at least a tiny bit more verbose information than the usage text.

I can try and come up with something soonish, however I'm still not yet very well acquainted with this library and its accompanying binary, so I would fear describing inaccurate information. I also don't know what formatting would be most desirable to you for the contents of the man page.

from what I can see so far, the pathspec-rb binary is a helper tool for testing matches of some values of pathspecs on a specified path. also there doesn't seem to be any configuration file involved. so the man page would probably be very simple.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

asdf
.tool-versions
  • ruby 3.3.0
bundler
Gemfile
github-actions
.github/workflows/gem-push.yml
  • actions/checkout v4
  • ruby/setup-ruby d4526a55538b775af234ba4af27118ed6f8f6677
.github/workflows/ruby.yml
  • actions/checkout v4
  • ruby/setup-ruby d4526a55538b775af234ba4af27118ed6f8f6677
  • actions/checkout v4
  • ruby/setup-ruby d4526a55538b775af234ba4af27118ed6f8f6677

  • Check this box to trigger a request for Renovate to run again on this repository

Release needs to happen for ~1.1.0~ 1.1.1

[x] Update changelog
[x] Ruby versions supported changed, updated minimum ruby version
[x] Some linting changes that should not effect anything
[x] tag
[x] tag again after forgetting about the allowed gem host update I did
[x] push to rubygems
[x] going to need to figure out how the new MFA based push works
[x] setup push to GH packages, as well? just going to push to rubygems at this time

Some missing bits according to the license

Hello,

While inspecting the codebase for preparing a debian package with it, I saw that there were some details that were missing according to the license that you've chosen for the codebase:

  • There should be a NOTICE file at the top
  • each source code file should have a short header comment that mentions the license and a copyright attribution

To find out more details about the two points, you can check out the following URL: https://infra.apache.org/apply-license.html

Ruby 2.5.0 Support

The specs fail with this error:

3) PathSpec#match_tree unix 
     Failure/Error:
       Find.find(root) do |path|
         relpath = Pathname.new(path).relative_path_from(rootpath).to_s
         relpath += '/' if File.directory? path
         if match(relpath)
           matching << path
         end
     
     NoMethodError:
       undefined method `children' for FakeFS::Dir:Class
     # ./lib/pathspec.rb:41:in `match_tree'
     # ./spec/unit/pathspec_spec.rb:191:in `block (4 levels) in <top (required)>'
     # ./spec/unit/pathspec_spec.rb:196:in `block (4 levels) in <top (required)>'

Problem with brackets on gitignore patter

I have a test on my pipeline for the gitignore file using the pathspec-ruby. Worked well with 0.2.1 but crashed with 1.0.0.
The error is this:

$ bundle exec rake syntax
rake aborted!
SyntaxError: /usr/local/bundle/gems/pathspec-1.0.0/lib/pathspec/gitignorespec.rb:45: syntax error, unexpected ']'
...         pattern = pattern[1..]
...                              ^
/usr/local/bundle/gems/pathspec-1.0.0/lib/pathspec/gitignorespec.rb:52: syntax error, unexpected ']'
        pattern = pattern[1..] if pattern.start_with?('\\')
                             ^
/usr/local/bundle/gems/pathspec-1.0.0/lib/pathspec.rb:1:in `require'
/usr/local/bundle/gems/pathspec-1.0.0/lib/pathspec.rb:1:in `<top (required)>'
/usr/local/bundle/gems/puppetlabs_spec_helper-2.16.0/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb:3:in `require'
/usr/local/bundle/gems/puppetlabs_spec_helper-2.16.0/lib/puppetlabs_spec_helper/tasks/check_symlinks.rb:3:in `<top (required)>'
/usr/local/bundle/gems/puppetlabs_spec_helper-2.16.0/lib/puppetlabs_spec_helper/rake_tasks.rb:11:in `require'
/usr/local/bundle/gems/puppetlabs_spec_helper-2.16.0/lib/puppetlabs_spec_helper/rake_tasks.rb:11:in `<top (required)>'
/builds/equinix-mse/control-repo/Rakefile:1:in `require'
/builds/equinix-mse/control-repo/Rakefile:1:in `<top (required)>'
/usr/local/bundle/gems/rake-13.0.3/exe/rake:27:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'

The only line with brackets on the gitignore is .*.sw[op]

Release 0.2.0

  • Bump version in gemspec and build script
  • Commit
  • Build gem, push gem
  • Tag
  • Hit release button on GH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.