Match Path Specifications, such as .gitignore, in Ruby!
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rubocop.yml
.rubocop_todo.yml
.travis.yml
CHANGELOG.md
Gemfile
LICENSE
README.md
Rakefile
install_from_source.sh
pathspec.gemspec
rspec_all_versions.sh

README.md

pathspec-ruby

Gem Version Build Status Maintainability

Supported Rubies:

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

➜  test-pathspec cat .gitignore
*.swp
/coverage/
➜  test-pathspec be pathspec-rb specs_match "coverage/foo"
/coverage/
➜  test-pathspec be pathspec-rb specs_match "file.swp"
*.swp
➜ test-pathspec be pathspec-rb match "file.swp"
➜ test-pathspec echo $?
0
➜  test-pathspec ls
Gemfile      Gemfile.lock coverage     file.swp     source.rb
➜  test-pathspec be 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.

Building/Installing from Source

git clone git@github.com: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.