gitignore-parser 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gitignore-parser.gemspec +27 -0
- data/lib/gitignore/parser.rb +9 -0
- data/lib/gitignore/parser/rule.rb +54 -0
- data/lib/gitignore/parser/scanner.rb +73 -0
- data/lib/gitignore/parser/version.rb +5 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1312b5d93955107db88d4ad9710782dc74c439222c7b944821e74844f5480f04
|
4
|
+
data.tar.gz: 0c8d238e9d707f6d0c1d829fb3f64fbbab14c42d4cf3a3fadb910d100202d87a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4d4b7cdb001d11419cdc797af2d3d3620b2fd09f69b8afca45b625bab9057d8fac513346b3da406c4cb8b8a84e777d9a52917913b44d3b1ca8dc9c5ccb42c54
|
7
|
+
data.tar.gz: 97c9e7758f34d60d672128a0a410988b8831d7d456a0561e32eb6c14ed887b8be1b4686dfe957d3077ddb9e47da692ae532c69ab4367feb59dae2b168cea369d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gitignore-parser (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
parallel (1.12.1)
|
12
|
+
parser (2.5.1.0)
|
13
|
+
ast (~> 2.4.0)
|
14
|
+
powerpack (0.1.1)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.7.0)
|
18
|
+
rspec-core (~> 3.7.0)
|
19
|
+
rspec-expectations (~> 3.7.0)
|
20
|
+
rspec-mocks (~> 3.7.0)
|
21
|
+
rspec-core (3.7.1)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-expectations (3.7.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-mocks (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-support (3.7.1)
|
30
|
+
rubocop (0.56.0)
|
31
|
+
parallel (~> 1.10)
|
32
|
+
parser (>= 2.5)
|
33
|
+
powerpack (~> 0.1)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
37
|
+
ruby-progressbar (1.9.0)
|
38
|
+
unicode-display_width (1.3.3)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 1.16)
|
45
|
+
gitignore-parser!
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
rubocop
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Gitignore::Parser
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitignore/parser`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gitignore-parser'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gitignore-parser
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitignore-parser.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'gitignore/parser'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gitignore/parser/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gitignore-parser'
|
8
|
+
spec.version = Gitignore::Parser::VERSION
|
9
|
+
spec.authors = ['hawknewton']
|
10
|
+
spec.email = ['hawk.newton@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'List files honoring .gitgnore'
|
13
|
+
spec.description = 'Lists files and directies accordingto .gitignore'
|
14
|
+
spec.homepage = 'https://github.com/hawknewton/gitignore-parser'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
27
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Gitignore::Parser::Rule
|
2
|
+
def initialize(pattern)
|
3
|
+
if pattern[0] == '!'
|
4
|
+
@unignore = true
|
5
|
+
pattern = pattern[1..-1]
|
6
|
+
else
|
7
|
+
@unignore = false
|
8
|
+
end
|
9
|
+
|
10
|
+
@pattern = pattern
|
11
|
+
end
|
12
|
+
|
13
|
+
def ignore?(path)
|
14
|
+
!unignore && matches?(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def unignore?(path)
|
18
|
+
unignore && matches?(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def for_dir(dir)
|
22
|
+
pattern = pattern_for_dir(dir)
|
23
|
+
return nil unless pattern
|
24
|
+
"#{unignore ? '!' : ''}#{pattern}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :pattern, :unignore
|
30
|
+
|
31
|
+
def comment?
|
32
|
+
pattern =~ /^#/
|
33
|
+
end
|
34
|
+
|
35
|
+
def glob
|
36
|
+
@glob ||= pattern.gsub(/((?<!\\)\s)+$/, '').gsub(%r{^\*\*/}, '').gsub(%r{^/}, '')
|
37
|
+
end
|
38
|
+
|
39
|
+
def matches?(path, match = glob)
|
40
|
+
return false if comment?
|
41
|
+
path = path.gsub(%r{/$}, '') if pattern[-1] != '/'
|
42
|
+
File.fnmatch(match, path)
|
43
|
+
end
|
44
|
+
|
45
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
46
|
+
def pattern_for_dir(dir)
|
47
|
+
(match, rest) = glob.split('/', 2)
|
48
|
+
return rest if match == '**'
|
49
|
+
return "#{rest[0..1] == '**' ? '' : '/'}#{rest}" if rest && matches?(dir, match)
|
50
|
+
return nil if pattern[0] == '/' || comment?
|
51
|
+
pattern
|
52
|
+
end
|
53
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Gitignore::Parser::Scanner
|
2
|
+
def initialize(opts)
|
3
|
+
@directory = opts[:directory]
|
4
|
+
@filename = opts[:filename]
|
5
|
+
@parent_patterns = opts[:parent_patterns] || []
|
6
|
+
end
|
7
|
+
|
8
|
+
def list_files
|
9
|
+
kept = files.map do |file|
|
10
|
+
if File.directory?(file)
|
11
|
+
list_directory(file)
|
12
|
+
else
|
13
|
+
list_file(file)
|
14
|
+
end
|
15
|
+
end.compact.flatten
|
16
|
+
|
17
|
+
kept + (files.reject { |f| File.directory?(f) } - kept).select do |filtered|
|
18
|
+
unignored?(filtered)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
attr_reader :directory, :parent_patterns
|
25
|
+
|
26
|
+
def list_directory(dir)
|
27
|
+
return [] if ignored?("#{dir}/")
|
28
|
+
dir_rules = rules_for_subdir(dir)
|
29
|
+
Gitignore::Parser::Scanner.new(directory: dir, filename: filename, parent_patterns: dir_rules).list_files
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_file(file)
|
33
|
+
return [] if ignored?(file)
|
34
|
+
[file]
|
35
|
+
end
|
36
|
+
|
37
|
+
def files
|
38
|
+
@files ||= Dir["#{directory}/*"]
|
39
|
+
end
|
40
|
+
|
41
|
+
def filename
|
42
|
+
@filename || '.gitignore'
|
43
|
+
end
|
44
|
+
|
45
|
+
def rules
|
46
|
+
@rules ||= patterns.map do |line|
|
47
|
+
Gitignore::Parser::Rule.new(line)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
%i[ignore unignore].each do |name|
|
52
|
+
define_method("#{name}d?") do |path|
|
53
|
+
rules.detect { |r| r.send("#{name}?", relative_path(path)) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def patterns
|
58
|
+
@patterns ||=
|
59
|
+
begin
|
60
|
+
gitignore = File.join(directory, filename)
|
61
|
+
return parent_patterns unless File.exist?(gitignore)
|
62
|
+
File.readlines(gitignore) + parent_patterns
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def relative_path(path)
|
67
|
+
path[directory.length + 1..-1]
|
68
|
+
end
|
69
|
+
|
70
|
+
def rules_for_subdir(path)
|
71
|
+
rules.map { |r| r.for_dir(relative_path(path)) }.compact
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitignore-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hawknewton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Lists files and directies accordingto .gitignore
|
70
|
+
email:
|
71
|
+
- hawk.newton@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- gitignore-parser.gemspec
|
87
|
+
- lib/gitignore/parser.rb
|
88
|
+
- lib/gitignore/parser/rule.rb
|
89
|
+
- lib/gitignore/parser/scanner.rb
|
90
|
+
- lib/gitignore/parser/version.rb
|
91
|
+
homepage: https://github.com/hawknewton/gitignore-parser
|
92
|
+
licenses: []
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.7.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: List files honoring .gitgnore
|
114
|
+
test_files: []
|