fast_ignore 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 +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +191 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +76 -0
- data/Rakefile +10 -0
- data/bin/console +8 -0
- data/bin/setup +8 -0
- data/fast_ignore.gemspec +36 -0
- data/lib/fast_ignore/file_rule_list.rb +11 -0
- data/lib/fast_ignore/gitignore_rule_list.rb +12 -0
- data/lib/fast_ignore/rule.rb +58 -0
- data/lib/fast_ignore/rule_list.rb +30 -0
- data/lib/fast_ignore/version.rb +5 -0
- data/lib/fast_ignore.rb +70 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6ccc7e9492f4e3b32cca4bbf1a758df089bfb1f3ae0f9a1f869b4aee8ce0666
|
4
|
+
data.tar.gz: fb760076616b071c946750ba77016e147c593fd9fc830eef4cb498cccbad6042
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1a96702300507bf80cc670011226ac905395e38115bf437ef8a6a46d13dea655022f9ea80e3ff02b206e12c3f8d2a9f3b174c8f29e3f8da6a2423d003c19c380
|
7
|
+
data.tar.gz: 56c3ce89f07434317bd45123a8dff81d66c1bf55652b0531ac4f17a96e3fd4428d1410b1a67a9a75573201c7f5ea30d7c0a543ae15a536df1f05883fd037ff5b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
# Reference:
|
4
|
+
# https://rubocop.readthedocs.io/en/latest/
|
5
|
+
|
6
|
+
# Keep this in alphabetical order.
|
7
|
+
# Each override should have a comment (even if it's just "default is bad")
|
8
|
+
|
9
|
+
AllCops:
|
10
|
+
Exclude:
|
11
|
+
- db/schema*
|
12
|
+
- .bundle/**/*
|
13
|
+
- tmp/**/*
|
14
|
+
DisplayCopNames: true
|
15
|
+
DisplayStyleGuide: true
|
16
|
+
|
17
|
+
# all of our layout customisations are because we prefer indentation to be
|
18
|
+
# always consistently 2 spaces, for blocks, scopes, multiline expressions, etc
|
19
|
+
# e.g.
|
20
|
+
# class Klass
|
21
|
+
# def method(arg1,
|
22
|
+
# arg2)
|
23
|
+
# value = if arg1 == 'value' && arg2 == 'value'
|
24
|
+
# method2
|
25
|
+
# .method(arg_a, arg_b,
|
26
|
+
# arg_c, arg_d, keyword1: true,
|
27
|
+
# keyword2: true) do
|
28
|
+
# @last = [
|
29
|
+
# arg_a, arg_b,
|
30
|
+
# arg_c, arg_d
|
31
|
+
# ]
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
# value
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
|
38
|
+
# to match our preference for consistent indentation
|
39
|
+
Layout/AlignHash:
|
40
|
+
EnforcedLastArgumentHashStyle: always_ignore
|
41
|
+
|
42
|
+
# to match our preference for consistent indentation
|
43
|
+
Layout/AlignParameters:
|
44
|
+
EnforcedStyle: with_fixed_indentation
|
45
|
+
|
46
|
+
# to match our preference for consistent indentation
|
47
|
+
Layout/BlockAlignment:
|
48
|
+
EnforcedStyleAlignWith: start_of_block
|
49
|
+
|
50
|
+
# to match our preference for consistent indentation
|
51
|
+
Layout/CaseIndentation:
|
52
|
+
EnforcedStyle: end
|
53
|
+
|
54
|
+
# to match our preference for consistent indentation
|
55
|
+
Layout/EndAlignment:
|
56
|
+
EnforcedStyleAlignWith: start_of_line
|
57
|
+
|
58
|
+
# Aligning Assignments, etc makes diffs noisy
|
59
|
+
Layout/ExtraSpacing:
|
60
|
+
AllowForAlignment: false
|
61
|
+
|
62
|
+
# to match our preference for consistent indentation
|
63
|
+
Layout/FirstArrayElementLineBreak:
|
64
|
+
Enabled: true
|
65
|
+
|
66
|
+
# to match our preference for consistent indentation
|
67
|
+
Layout/FirstHashElementLineBreak:
|
68
|
+
Enabled: true
|
69
|
+
|
70
|
+
# to match our preference for consistent indentation
|
71
|
+
Layout/FirstParameterIndentation:
|
72
|
+
EnforcedStyle: consistent
|
73
|
+
|
74
|
+
# to match our preference for consistent indentation
|
75
|
+
Layout/IndentArray:
|
76
|
+
EnforcedStyle: consistent
|
77
|
+
|
78
|
+
# to match our preference for consistent indentation
|
79
|
+
Layout/IndentHash:
|
80
|
+
EnforcedStyle: consistent
|
81
|
+
|
82
|
+
# to match our preference for consistent indentation
|
83
|
+
# and hanging assignment looks lost
|
84
|
+
Layout/MultilineAssignmentLayout:
|
85
|
+
EnforcedStyle: same_line
|
86
|
+
|
87
|
+
# this changes our preferred:
|
88
|
+
# value = if thing1 &&
|
89
|
+
# thing2
|
90
|
+
# to:
|
91
|
+
# value = if thing1 &&
|
92
|
+
# thing2
|
93
|
+
# even though the IndentationWidth is 2
|
94
|
+
# but it's right most of the time so I put up with it
|
95
|
+
Layout/MultilineOperationIndentation:
|
96
|
+
EnforcedStyle: indented
|
97
|
+
|
98
|
+
Layout/MultilineMethodCallIndentation:
|
99
|
+
EnforcedStyle: indented
|
100
|
+
|
101
|
+
# Temporarily disable this spec as a recent change has broken it for us:
|
102
|
+
# https://github.com/rubocop-hq/rubocop/issues/6254
|
103
|
+
Layout/RescueEnsureAlignment:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
Metrics:
|
107
|
+
CountComments: false
|
108
|
+
|
109
|
+
Metrics/BlockLength:
|
110
|
+
ExcludedMethods:
|
111
|
+
- configure
|
112
|
+
- describe
|
113
|
+
- context
|
114
|
+
- shared_examples
|
115
|
+
|
116
|
+
Metrics/LineLength:
|
117
|
+
Max: 120
|
118
|
+
|
119
|
+
RSpec:
|
120
|
+
Enabled: true
|
121
|
+
Include:
|
122
|
+
- 'spec/**/*.rb'
|
123
|
+
|
124
|
+
RSpec/DescribeClass:
|
125
|
+
Enabled: false
|
126
|
+
|
127
|
+
# I misuse matchers often
|
128
|
+
RSpec/ExpectActual:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
RSpec/FilePath:
|
132
|
+
Enabled: false
|
133
|
+
|
134
|
+
# Multiple expectations are useful
|
135
|
+
# checking you've partially achieved something on the way to completely achieving it is useful for debugging failures
|
136
|
+
RSpec/MultipleExpectations:
|
137
|
+
Enabled: false
|
138
|
+
|
139
|
+
# It should be obvious from context. Chill out rubocop
|
140
|
+
RSpec/NamedSubject:
|
141
|
+
Enabled: false
|
142
|
+
|
143
|
+
RSpec/NestedGroups:
|
144
|
+
Max: 7
|
145
|
+
|
146
|
+
# This matches the style we've been using all along (ever so slightly more frequently)
|
147
|
+
Style/Alias:
|
148
|
+
EnforcedStyle: prefer_alias_method
|
149
|
+
|
150
|
+
Style/CollectionMethods:
|
151
|
+
Enabled: true
|
152
|
+
|
153
|
+
# we don't rdoc
|
154
|
+
Style/Documentation:
|
155
|
+
Enabled: false
|
156
|
+
|
157
|
+
# this can mess with the balance of symmetric cases
|
158
|
+
Style/IfInsideElse:
|
159
|
+
Enabled: false
|
160
|
+
|
161
|
+
# [a, b].include?(x) is more unclear than a == x || b == x
|
162
|
+
Style/MultipleComparison:
|
163
|
+
Enabled: false
|
164
|
+
|
165
|
+
# we use %w{} pretty frequently
|
166
|
+
Style/PercentLiteralDelimiters:
|
167
|
+
PreferredDelimiters:
|
168
|
+
default: '{}'
|
169
|
+
'%w': '{}'
|
170
|
+
'%W': '{}'
|
171
|
+
'%i': '{}'
|
172
|
+
'%I': '{}'
|
173
|
+
'%r': '{}'
|
174
|
+
|
175
|
+
# We want this to warn to force consistency within the codebase.
|
176
|
+
Style/SafeNavigation:
|
177
|
+
Enabled: true
|
178
|
+
|
179
|
+
# different methods calls that do exactly the same thing are a smell, regardless of semantics
|
180
|
+
Style/SignalException:
|
181
|
+
EnforcedStyle: only_raise
|
182
|
+
|
183
|
+
# this wants less descriptive names
|
184
|
+
Style/SingleLineBlockParams:
|
185
|
+
Enabled: false
|
186
|
+
|
187
|
+
Style/SymbolArray:
|
188
|
+
Enabled: false
|
189
|
+
|
190
|
+
Style/WordArray:
|
191
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fast_ignore (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
jaro_winkler (1.5.2)
|
13
|
+
method_source (0.9.2)
|
14
|
+
parallel (1.15.0)
|
15
|
+
parser (2.6.2.0)
|
16
|
+
ast (~> 2.4.0)
|
17
|
+
pry (0.12.2)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
psych (3.1.0)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.8.0)
|
24
|
+
rspec-core (~> 3.8.0)
|
25
|
+
rspec-expectations (~> 3.8.0)
|
26
|
+
rspec-mocks (~> 3.8.0)
|
27
|
+
rspec-core (3.8.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-expectations (3.8.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-mocks (3.8.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-support (3.8.0)
|
36
|
+
rubocop (0.66.0)
|
37
|
+
jaro_winkler (~> 1.5.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.5, != 2.5.1.1)
|
40
|
+
psych (>= 3.1.0)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
ruby-progressbar (~> 1.7)
|
43
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
44
|
+
rubocop-rspec (1.32.0)
|
45
|
+
rubocop (>= 0.60.0)
|
46
|
+
ruby-progressbar (1.10.0)
|
47
|
+
unicode-display_width (1.5.0)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bundler (~> 1.17)
|
54
|
+
fast_ignore!
|
55
|
+
pry
|
56
|
+
rake (~> 10.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
rubocop
|
59
|
+
rubocop-rspec
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Dana Sherson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# FastIgnore
|
2
|
+
|
3
|
+
![travis](https://travis-ci.org/robotdana/fast_ignore.svg?branch=master)
|
4
|
+
|
5
|
+
Filter a directory using a .gitignore file. Follows all the gitignore formatting rules including `!dir` and `/dir`
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'fast_ignore'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install fast_ignore
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
```ruby
|
25
|
+
FastIgnore.new.each { |file| puts "#{file} is not ignored by the .gitignore" }
|
26
|
+
```
|
27
|
+
|
28
|
+
Like many other enumerables, FastIgnore.new.each can return an enumerator
|
29
|
+
```ruby
|
30
|
+
FastIgnore.new.each.with_index { |file, index| puts "#{file}#{index}" }
|
31
|
+
```
|
32
|
+
|
33
|
+
By default, FastIgnore will return full paths. To return paths relative to the current working directory, use:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
FastIgnore.new(relative: true).to_a
|
37
|
+
```
|
38
|
+
|
39
|
+
You can specify other gitignore-style files to ignore as well. These rules will be appended after the gitignore file in order (order matters for negations)
|
40
|
+
```ruby
|
41
|
+
FastIgnore.new(files: '/path/to/my/ignore/file').to_a
|
42
|
+
FastIgnore.new(files: ['/path/to/my/ignore/file', '/and/another']).to_a
|
43
|
+
```
|
44
|
+
|
45
|
+
You can also supply an array of rule lines. These rules will be appended after the gitignore and any other files in order (order matters for negations)
|
46
|
+
```ruby
|
47
|
+
FastIgnore.new(rules: '.DS_Store').to_a
|
48
|
+
FastIgnore.new(rules: ['.git', '.gitkeep']).to_a
|
49
|
+
```
|
50
|
+
|
51
|
+
By default, FastIgnore will look in the directory the script is run in (PWD) for a gitignore file. If it's somewhere else,
|
52
|
+
```ruby
|
53
|
+
FastIgnore.new(rules: '.git', files: '/path/to/.gitignore', gitignore: false).to_a
|
54
|
+
FastIgnore.new(rules: '.git', files: ['/path/to/.gitignore', '/path/to/other/excludesfile'], gitignore: false).to_a
|
55
|
+
```
|
56
|
+
(You need the rules: '.git' because we're excluding the normal gitignore file)
|
57
|
+
|
58
|
+
## Known issues/TODOs
|
59
|
+
- Considers rules relative to the location of the gitignore file, to always be relative to PWD instead
|
60
|
+
- Can't override path to gitignore file nicley, Ideally it would be `FastIgnore.new(gitignore: path)`
|
61
|
+
- Doesn't take into account ignored project excludes in `.git/info/exclude`
|
62
|
+
- Doesn't take into account globally ignored files in `git config core.excludesFile`
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
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.
|
67
|
+
|
68
|
+
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).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/robotdana/fast_ignore.
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/fast_ignore.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'fast_ignore/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'fast_ignore'
|
9
|
+
spec.version = FastIgnore::VERSION
|
10
|
+
spec.authors = ['Dana Sherson']
|
11
|
+
spec.email = ['robot@dana.sh']
|
12
|
+
|
13
|
+
spec.summary = 'Parse gitignore files'
|
14
|
+
spec.homepage = 'https://github.com/robotdana/fast_ignore'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
spec.metadata['source_code_uri'] = 'https://github.com/robotdana/fast_ignore'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/robotdana/fast_ignore/CHANGELOG'
|
21
|
+
end
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 0'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1'
|
36
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FastIgnore
|
4
|
+
class GitignoreRuleList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def each(&block)
|
8
|
+
FastIgnore::RuleList.new('.git').each(&block)
|
9
|
+
FastIgnore::FileRuleList.new(File.join(Dir.pwd, '.gitignore')).each(&block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FastIgnore
|
4
|
+
class Rule
|
5
|
+
def initialize(rule)
|
6
|
+
@rule = rule
|
7
|
+
strip!
|
8
|
+
return if skip?
|
9
|
+
|
10
|
+
@rule = @rule.delete_prefix('!') if negation?
|
11
|
+
@rule = @rule.delete_suffix('/') if dir_only?
|
12
|
+
@rule = "#{prefix}#{@rule}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def negation?
|
16
|
+
@negation ||= @rule.start_with?('!')
|
17
|
+
end
|
18
|
+
|
19
|
+
def dir_only?
|
20
|
+
@dir_only ||= @rule.end_with?('/')
|
21
|
+
end
|
22
|
+
|
23
|
+
def match?(path, dir)
|
24
|
+
return false if !dir && dir_only?
|
25
|
+
|
26
|
+
File.fnmatch?(@rule, path, File::FNM_DOTMATCH | File::FNM_PATHNAME)
|
27
|
+
end
|
28
|
+
|
29
|
+
def empty?
|
30
|
+
@empty ||= @rule.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def comment?
|
34
|
+
@comment ||= @rule.start_with?('#')
|
35
|
+
end
|
36
|
+
|
37
|
+
def skip?
|
38
|
+
empty? || comment?
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def prefix
|
44
|
+
@prefix ||= if @rule.start_with?('/')
|
45
|
+
''
|
46
|
+
elsif @rule.end_with?('/**') || @rule.include?('/**/')
|
47
|
+
'/'
|
48
|
+
else
|
49
|
+
'**/'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def strip!
|
54
|
+
@rule = @rule.chomp
|
55
|
+
@rule = @rule.rstrip unless @rule.end_with?('\\ ')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class FastIgnore
|
4
|
+
class RuleList
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(*lines)
|
8
|
+
@lines = lines
|
9
|
+
end
|
10
|
+
|
11
|
+
def each(&block)
|
12
|
+
return enumerator unless block_given?
|
13
|
+
|
14
|
+
enumerator.each(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :lines
|
20
|
+
|
21
|
+
def enumerator
|
22
|
+
Enumerator.new do |yielder|
|
23
|
+
lines.reverse_each do |rule|
|
24
|
+
rule = FastIgnore::Rule.new(rule)
|
25
|
+
yielder << rule unless rule.skip?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/fast_ignore.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './fast_ignore/rule'
|
4
|
+
require_relative './fast_ignore/rule_list'
|
5
|
+
require_relative './fast_ignore/file_rule_list'
|
6
|
+
require_relative './fast_ignore/gitignore_rule_list'
|
7
|
+
|
8
|
+
require 'find'
|
9
|
+
|
10
|
+
class FastIgnore
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
attr_reader :rules, :relative
|
14
|
+
alias_method :relative?, :relative
|
15
|
+
|
16
|
+
def initialize(rules: nil, files: nil, gitignore: true, relative: false)
|
17
|
+
@relative = relative
|
18
|
+
@rules = []
|
19
|
+
@rules += FastIgnore::RuleList.new(*Array(rules)).to_a
|
20
|
+
Array(files).reverse_each do |file|
|
21
|
+
@rules += FastIgnore::FileRuleList.new(file).to_a
|
22
|
+
end
|
23
|
+
@rules += FastIgnore::GitignoreRuleList.new.to_a if gitignore
|
24
|
+
end
|
25
|
+
|
26
|
+
def enumerator
|
27
|
+
Enumerator.new do |yielder|
|
28
|
+
Find.find(root) do |path|
|
29
|
+
dir = File.directory?(path)
|
30
|
+
next if path == root
|
31
|
+
next Find.prune unless pruned_allowed?(path, dir: dir)
|
32
|
+
next if dir
|
33
|
+
|
34
|
+
path = path.delete_prefix("#{root}/") if relative?
|
35
|
+
|
36
|
+
yielder << path
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def root
|
42
|
+
@root ||= Dir.pwd
|
43
|
+
end
|
44
|
+
|
45
|
+
def allowed?(path, dir: File.directory?(path))
|
46
|
+
return true if path == root
|
47
|
+
|
48
|
+
allowed?(File.dirname(path), dir: true) && pruned_allowed?(path, dir: dir)
|
49
|
+
end
|
50
|
+
|
51
|
+
def pruned_allowed?(path, dir: File.directory?(path))
|
52
|
+
path = path.delete_prefix(root)
|
53
|
+
|
54
|
+
rules.each do |rule|
|
55
|
+
return rule.negation? if rule.match?(path, dir)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def each(&block)
|
60
|
+
if block_given?
|
61
|
+
enumerator.each(&block)
|
62
|
+
else
|
63
|
+
enumerator
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def files
|
68
|
+
to_a
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast_ignore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dana Sherson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-06 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- robot@dana.sh
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".ruby-version"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- fast_ignore.gemspec
|
117
|
+
- lib/fast_ignore.rb
|
118
|
+
- lib/fast_ignore/file_rule_list.rb
|
119
|
+
- lib/fast_ignore/gitignore_rule_list.rb
|
120
|
+
- lib/fast_ignore/rule.rb
|
121
|
+
- lib/fast_ignore/rule_list.rb
|
122
|
+
- lib/fast_ignore/version.rb
|
123
|
+
homepage: https://github.com/robotdana/fast_ignore
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata:
|
127
|
+
homepage_uri: https://github.com/robotdana/fast_ignore
|
128
|
+
source_code_uri: https://github.com/robotdana/fast_ignore
|
129
|
+
changelog_uri: https://github.com/robotdana/fast_ignore/CHANGELOG
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.7.6
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Parse gitignore files
|
150
|
+
test_files: []
|