fast_ignore 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +4 -4
- data/README.md +20 -10
- data/fast_ignore.gemspec +2 -2
- data/lib/fast_ignore/file_rule_list.rb +2 -1
- data/lib/fast_ignore/gitignore_rule_list.rb +9 -1
- data/lib/fast_ignore/rule.rb +7 -2
- data/lib/fast_ignore/rule_list.rb +4 -3
- data/lib/fast_ignore/version.rb +1 -1
- data/lib/fast_ignore.rb +30 -29
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4c51ea85828e7c8659e7e67c6b4f72a577e463439412da55842d2ccdc8cb2be
|
4
|
+
data.tar.gz: c9cfdfcfa66b2df5b927ce0a53f094cf72c1a9db33f09cf992e7d1337fc9a37a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f25671f6eff33fdd7a56cdda01941413b0de30fa35eca7aee5f495414335fb5b48eff2ed67c19a7c2638483c7e7ba10069e42e41ae099da577af9772b3c66680
|
7
|
+
data.tar.gz: 6b64940f041f0ce7edeb913ea01d030f92925fdae4ad454e4ca84ccd373e02779ac2b234d2645a9bab823547a9775c1f41547001077557c90fa33d83b5dc7a0c
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# v0.2.0
|
2
|
+
- Considers rules relative to the location of the gitignore file instead of just relative to PWD
|
3
|
+
- Can override the path to the gitignore file, using `FastIgnore.new(gitignore: path)`
|
4
|
+
- Mention FastIgnore#allowed? in the documentation.
|
5
|
+
|
6
|
+
# v0.1.0
|
7
|
+
Initial Release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fast_ignore (0.
|
4
|
+
fast_ignore (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -52,11 +52,11 @@ PLATFORMS
|
|
52
52
|
DEPENDENCIES
|
53
53
|
bundler (~> 1.17)
|
54
54
|
fast_ignore!
|
55
|
-
pry
|
55
|
+
pry (~> 0)
|
56
56
|
rake (~> 10.0)
|
57
57
|
rspec (~> 3.0)
|
58
|
-
rubocop
|
59
|
-
rubocop-rspec
|
58
|
+
rubocop (~> 0)
|
59
|
+
rubocop-rspec (~> 1)
|
60
60
|
|
61
61
|
BUNDLED WITH
|
62
62
|
1.17.1
|
data/README.md
CHANGED
@@ -38,29 +38,39 @@ FastIgnore.new(relative: true).to_a
|
|
38
38
|
|
39
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
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
|
41
|
+
FastIgnore.new(files: '/absolute/path/to/my/ignore/file').to_a
|
42
|
+
FastIgnore.new(files: ['/absolute/path/to/my/ignore/file', '/and/another']).to_a
|
43
43
|
```
|
44
|
-
|
45
44
|
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
45
|
```ruby
|
47
46
|
FastIgnore.new(rules: '.DS_Store').to_a
|
48
47
|
FastIgnore.new(rules: ['.git', '.gitkeep']).to_a
|
49
48
|
```
|
50
49
|
|
51
|
-
|
50
|
+
To only use another ignore file or set of rules, and not try to load a gitignore file:
|
51
|
+
```ruby
|
52
|
+
FastIgnore.new(files: 'absolute/path/to/my/ignore/file', gitignore: false)
|
53
|
+
FastIgnore.new(rules: %w{my*rule /and/another !rule}, gitignore: false)
|
54
|
+
```
|
55
|
+
|
56
|
+
By default, FastIgnore will look in the directory the script is run in (PWD) for a gitignore file. If it's somewhere else:
|
52
57
|
```ruby
|
53
|
-
FastIgnore.new(
|
54
|
-
|
58
|
+
FastIgnore.new(gitignore: '/absolute/path/to/.gitignore').to_a
|
59
|
+
```
|
60
|
+
Note that the location of the .gitignore file will affect things like rules beginning with `/` or ending in `/**`
|
61
|
+
|
62
|
+
To check if a single file is allowed, use
|
63
|
+
```ruby
|
64
|
+
FastIgnore.new.allowed?('/absolute/path/to/file')
|
55
65
|
```
|
56
|
-
(You need the rules: '.git' because we're excluding the normal gitignore file)
|
57
66
|
|
58
67
|
## 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
68
|
- Doesn't take into account ignored project excludes in `.git/info/exclude`
|
62
69
|
- Doesn't take into account globally ignored files in `git config core.excludesFile`
|
63
|
-
|
70
|
+
This is probably a wontfix, as you need git to read the config, and may as well just
|
71
|
+
```ruby
|
72
|
+
`git ls-files`.split("\n")
|
73
|
+
```
|
64
74
|
## Development
|
65
75
|
|
66
76
|
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.
|
data/fast_ignore.gemspec
CHANGED
@@ -10,14 +10,14 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Dana Sherson']
|
11
11
|
spec.email = ['robot@dana.sh']
|
12
12
|
|
13
|
-
spec.summary = 'Parse gitignore files'
|
13
|
+
spec.summary = 'Parse gitignore files, quickly'
|
14
14
|
spec.homepage = 'https://github.com/robotdana/fast_ignore'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
if spec.respond_to?(:metadata)
|
18
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
19
19
|
spec.metadata['source_code_uri'] = 'https://github.com/robotdana/fast_ignore'
|
20
|
-
spec.metadata['changelog_uri'] = 'https://github.com/robotdana/fast_ignore/CHANGELOG'
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/robotdana/fast_ignore/blob/master/CHANGELOG.md'
|
21
21
|
end
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
@@ -4,9 +4,17 @@ class FastIgnore
|
|
4
4
|
class GitignoreRuleList
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
+
def initialize(file)
|
8
|
+
@file = file
|
9
|
+
end
|
10
|
+
|
7
11
|
def each(&block)
|
8
12
|
FastIgnore::RuleList.new('.git').each(&block)
|
9
|
-
FastIgnore::FileRuleList.new(
|
13
|
+
FastIgnore::FileRuleList.new(file).each(&block)
|
10
14
|
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :file
|
11
19
|
end
|
12
20
|
end
|
data/lib/fast_ignore/rule.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
class FastIgnore
|
4
4
|
class Rule
|
5
|
-
def initialize(rule)
|
5
|
+
def initialize(rule, root: Dir.pwd)
|
6
|
+
@root = root
|
6
7
|
@rule = rule
|
7
8
|
strip!
|
8
9
|
return if skip?
|
@@ -20,9 +21,11 @@ class FastIgnore
|
|
20
21
|
@dir_only ||= @rule.end_with?('/')
|
21
22
|
end
|
22
23
|
|
23
|
-
def match?(path, dir)
|
24
|
+
def match?(path, dir: File.directory?(path))
|
24
25
|
return false if !dir && dir_only?
|
25
26
|
|
27
|
+
path = path.delete_prefix(root)
|
28
|
+
|
26
29
|
File.fnmatch?(@rule, path, File::FNM_DOTMATCH | File::FNM_PATHNAME)
|
27
30
|
end
|
28
31
|
|
@@ -40,6 +43,8 @@ class FastIgnore
|
|
40
43
|
|
41
44
|
private
|
42
45
|
|
46
|
+
attr_reader :root
|
47
|
+
|
43
48
|
def prefix
|
44
49
|
@prefix ||= if @rule.start_with?('/')
|
45
50
|
''
|
@@ -4,8 +4,9 @@ class FastIgnore
|
|
4
4
|
class RuleList
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
-
def initialize(*lines)
|
7
|
+
def initialize(*lines, root: Dir.pwd)
|
8
8
|
@lines = lines
|
9
|
+
@root = root
|
9
10
|
end
|
10
11
|
|
11
12
|
def each(&block)
|
@@ -16,12 +17,12 @@ class FastIgnore
|
|
16
17
|
|
17
18
|
private
|
18
19
|
|
19
|
-
attr_reader :lines
|
20
|
+
attr_reader :lines, :root
|
20
21
|
|
21
22
|
def enumerator
|
22
23
|
Enumerator.new do |yielder|
|
23
24
|
lines.reverse_each do |rule|
|
24
|
-
rule = FastIgnore::Rule.new(rule)
|
25
|
+
rule = FastIgnore::Rule.new(rule, root: root)
|
25
26
|
yielder << rule unless rule.skip?
|
26
27
|
end
|
27
28
|
end
|
data/lib/fast_ignore/version.rb
CHANGED
data/lib/fast_ignore.rb
CHANGED
@@ -10,19 +10,44 @@ require 'find'
|
|
10
10
|
class FastIgnore
|
11
11
|
include Enumerable
|
12
12
|
|
13
|
-
attr_reader :rules
|
13
|
+
attr_reader :rules
|
14
|
+
attr_reader :relative
|
14
15
|
alias_method :relative?, :relative
|
16
|
+
attr_reader :root
|
15
17
|
|
16
|
-
def initialize(
|
17
|
-
|
18
|
+
def initialize(
|
19
|
+
rules: nil,
|
20
|
+
files: nil,
|
21
|
+
relative: false,
|
22
|
+
root: Dir.pwd,
|
23
|
+
gitignore: File.join(root, '.gitignore')
|
24
|
+
)
|
18
25
|
@rules = []
|
19
26
|
@rules += FastIgnore::RuleList.new(*Array(rules)).to_a
|
20
27
|
Array(files).reverse_each do |file|
|
21
28
|
@rules += FastIgnore::FileRuleList.new(file).to_a
|
22
29
|
end
|
23
|
-
@rules += FastIgnore::GitignoreRuleList.new.to_a if gitignore
|
30
|
+
@rules += FastIgnore::GitignoreRuleList.new(gitignore).to_a if gitignore
|
31
|
+
@relative = relative
|
32
|
+
@root = root
|
33
|
+
end
|
34
|
+
|
35
|
+
def each(&block)
|
36
|
+
if block_given?
|
37
|
+
enumerator.each(&block)
|
38
|
+
else
|
39
|
+
enumerator
|
40
|
+
end
|
24
41
|
end
|
25
42
|
|
43
|
+
def allowed?(path, dir: File.directory?(path))
|
44
|
+
return true if path == root
|
45
|
+
|
46
|
+
allowed?(File.dirname(path), dir: true) && pruned_allowed?(path, dir: dir)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
26
51
|
def enumerator
|
27
52
|
Enumerator.new do |yielder|
|
28
53
|
Find.find(root) do |path|
|
@@ -38,33 +63,9 @@ class FastIgnore
|
|
38
63
|
end
|
39
64
|
end
|
40
65
|
|
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
66
|
def pruned_allowed?(path, dir: File.directory?(path))
|
52
|
-
path = path.delete_prefix(root)
|
53
|
-
|
54
67
|
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
|
68
|
+
return rule.negation? if rule.match?(path, dir: dir)
|
64
69
|
end
|
65
70
|
end
|
66
|
-
|
67
|
-
def files
|
68
|
-
to_a
|
69
|
-
end
|
70
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_ignore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dana Sherson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".rubocop.yml"
|
107
107
|
- ".ruby-version"
|
108
108
|
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
109
110
|
- Gemfile
|
110
111
|
- Gemfile.lock
|
111
112
|
- LICENSE.txt
|
@@ -126,7 +127,7 @@ licenses:
|
|
126
127
|
metadata:
|
127
128
|
homepage_uri: https://github.com/robotdana/fast_ignore
|
128
129
|
source_code_uri: https://github.com/robotdana/fast_ignore
|
129
|
-
changelog_uri: https://github.com/robotdana/fast_ignore/CHANGELOG
|
130
|
+
changelog_uri: https://github.com/robotdana/fast_ignore/blob/master/CHANGELOG.md
|
130
131
|
post_install_message:
|
131
132
|
rdoc_options: []
|
132
133
|
require_paths:
|
@@ -146,5 +147,5 @@ rubyforge_project:
|
|
146
147
|
rubygems_version: 2.7.6
|
147
148
|
signing_key:
|
148
149
|
specification_version: 4
|
149
|
-
summary: Parse gitignore files
|
150
|
+
summary: Parse gitignore files, quickly
|
150
151
|
test_files: []
|