fast_ignore 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +6 -2
- data/CHANGELOG.md +5 -0
- data/README.md +17 -8
- data/lib/fast_ignore.rb +35 -40
- data/lib/fast_ignore/rule.rb +7 -1
- data/lib/fast_ignore/rule_parser.rb +35 -32
- data/lib/fast_ignore/rule_set.rb +9 -5
- data/lib/fast_ignore/rule_set_builder.rb +33 -30
- data/lib/fast_ignore/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55e2502678383f7dec077fb00816f754ca795d6de214ae2950fd2343852e450b
|
4
|
+
data.tar.gz: ef25eca3ec9c85578f4c74a808f5865d5586d2ce5919b976013723f6d17beedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7dbfbe53878ac26d8b857647da3356b47c687f081f5369270d41576b71b414fc5b6417d8ed0b7c9d72a7bd65e1c727760573586a223c23a16126ad64ac72a099
|
7
|
+
data.tar.gz: 761d4d757d5660058be97dff4809415070bf610c8c5aa000e71bec1d36c3b7fcfdfe35e8ab1daf4586154d34d341a93dcf76f9055f942465bc7ae6a7cc280e9d
|
data/.simplecov
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
SimpleCov.start do
|
2
2
|
add_filter '/backports'
|
3
3
|
add_filter '/spec/'
|
4
|
-
|
5
|
-
|
4
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5')
|
5
|
+
enable_coverage(:branch)
|
6
|
+
minimum_coverage line: 100, branch: 100
|
7
|
+
else
|
8
|
+
minimum_coverage 100
|
9
|
+
end
|
6
10
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# v0.9.0
|
2
|
+
- speed improvements, which may break things (Specifically, only using relative paths internally, is about 30% faster (depending on root depth))
|
3
|
+
- using a `ignore_files:` or `include_files:` that are outside the `root: (default $PWD)` will now raise an error.
|
4
|
+
- remove deprecated `gitignore:` a path (e.g. `gitignore: '/path/to/gitignore'`). please use `gitignore: false, ignore_files: '/path/to/gitignore'` instead.
|
5
|
+
|
1
6
|
# v0.8.3
|
2
7
|
- fix `ignore_rules` not matching directories when using `include_shebangs:`
|
3
8
|
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
[![travis](https://travis-ci.org/robotdana/fast_ignore.svg?branch=master)](https://travis-ci.org/robotdana/fast_ignore)
|
4
4
|
|
5
|
+
This started as a way to quickly and natively ruby-ly parse gitignore files and find matching files.
|
6
|
+
It's now gained an equivalent includes file functionality, ARGV awareness, and some shebang matching, while still being extremely fast, to be a one-stop file-list for your linter.
|
7
|
+
|
5
8
|
Filter a directory tree using a .gitignore file. Recognises all of the [gitignore rules](https://www.git-scm.com/docs/gitignore#_pattern_format) ([except one](#known-issues))
|
6
9
|
|
7
10
|
```ruby
|
@@ -43,6 +46,12 @@ By default, FastIgnore will return full paths. To return paths relative to the c
|
|
43
46
|
FastIgnore.new(relative: true).to_a
|
44
47
|
```
|
45
48
|
|
49
|
+
By default, FastIgnore will look at the current working directory (PWD) for looking for .gitignore files, handling array rules, and the path that relative returns.
|
50
|
+
To use a different directory:
|
51
|
+
```ruby
|
52
|
+
FastIgnore.new(root: '/absolute/path/to/root').to_a
|
53
|
+
```
|
54
|
+
|
46
55
|
You can specify other gitignore-style files to ignore as well. Missing files will raise an `Errno::ENOENT` error.
|
47
56
|
|
48
57
|
```ruby
|
@@ -59,11 +68,11 @@ FastIgnore.new(ignore_rules: ['.git', '.gitkeep']).to_a
|
|
59
68
|
|
60
69
|
To use only another ignore file or an array of rules, and not even try to load a gitignore file:
|
61
70
|
```ruby
|
62
|
-
FastIgnore.new(ignore_files: '/absolute/path/to/my/ignore/file', gitignore: false)
|
63
|
-
FastIgnore.new(ignore_rules: %w{my*rule /and/another !rule}, gitignore: false)
|
71
|
+
FastIgnore.new(ignore_files: '/absolute/path/to/my/ignore/file', gitignore: false).to_a
|
72
|
+
FastIgnore.new(ignore_rules: %w{my*rule /and/another !rule}, gitignore: false).to_a
|
64
73
|
```
|
65
74
|
|
66
|
-
By default, FastIgnore will look in the directory
|
75
|
+
By default, FastIgnore will look in the root directory for a gitignore file. If it's somewhere else:
|
67
76
|
```ruby
|
68
77
|
FastIgnore.new(ignore_file: '/absolute/path/to/.gitignore', gitignore: false).to_a
|
69
78
|
```
|
@@ -108,14 +117,14 @@ fo*
|
|
108
117
|
|
109
118
|
These can be passed either as files or as an array or string rules
|
110
119
|
```ruby
|
111
|
-
FastIgnore.new(include_files: '/absolute/path/to/my/include/file', gitignore: false)
|
112
|
-
FastIgnore.new(include_rules: %w{my*rule /and/another !rule}, gitignore: false)
|
120
|
+
FastIgnore.new(include_files: '/absolute/path/to/my/include/file', gitignore: false).to_a
|
121
|
+
FastIgnore.new(include_rules: %w{my*rule /and/another !rule}, gitignore: false).to_a
|
113
122
|
```
|
114
123
|
|
115
124
|
There is an additional argument meant for dealing with humans and `ARGV` values.
|
116
125
|
|
117
126
|
```ruby
|
118
|
-
FastIgnore.new(argv_rules: ['./a/pasted/path', '/or/a/path/from/stdin', 'an/argument', '*.txt'])
|
127
|
+
FastIgnore.new(argv_rules: ['./a/pasted/path', '/or/a/path/from/stdin', 'an/argument', '*.txt']).to_a
|
119
128
|
```
|
120
129
|
|
121
130
|
It resolves absolute paths, and paths beginning with `~`, `../` and `./` (with and without `!`)
|
@@ -130,13 +139,13 @@ In the simplest case a file must be allowed by each ignore file, each include fi
|
|
130
139
|
To combine files using `OR`, that is, a file may be included by either file it doesn't have to be referred to in both:
|
131
140
|
|
132
141
|
```ruby
|
133
|
-
FastIgnore.new(include_files: StringIO.new([File.read('/my/path'), File.read('/another/path')]).join("\n"))
|
142
|
+
FastIgnore.new(include_files: StringIO.new([File.read('/my/path'), File.read('/another/path')]).join("\n")).to_a
|
134
143
|
```
|
135
144
|
|
136
145
|
To use the additional ARGV handling rules mentioned above for files
|
137
146
|
|
138
147
|
```ruby
|
139
|
-
FastIgnore.new(argv_rules: ["my/rule", File.read('/my/path')])
|
148
|
+
FastIgnore.new(argv_rules: ["my/rule", File.read('/my/path')]).to_a
|
140
149
|
```
|
141
150
|
|
142
151
|
## Known issues
|
data/lib/fast_ignore.rb
CHANGED
@@ -8,6 +8,8 @@ require_relative './fast_ignore/rule_set'
|
|
8
8
|
require_relative './fast_ignore/rule'
|
9
9
|
|
10
10
|
class FastIgnore
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
11
13
|
include ::Enumerable
|
12
14
|
|
13
15
|
# :nocov:
|
@@ -20,34 +22,25 @@ class FastIgnore
|
|
20
22
|
end
|
21
23
|
# :nocov:
|
22
24
|
|
23
|
-
def initialize(
|
25
|
+
def initialize(
|
24
26
|
relative: false,
|
25
27
|
root: ::Dir.pwd,
|
26
|
-
ignore_rules: nil,
|
27
|
-
ignore_files: nil,
|
28
|
-
gitignore: :auto,
|
29
|
-
include_rules: nil,
|
30
|
-
include_files: nil,
|
31
28
|
include_shebangs: nil,
|
32
|
-
|
29
|
+
**rule_set_builder_args
|
33
30
|
)
|
34
|
-
@root = root.
|
35
|
-
@root_trailing_slash = "#{@root}/"
|
31
|
+
@root = root.end_with?('/') ? root : "#{root}/"
|
36
32
|
@shebang_pattern = prepare_shebang_pattern(include_shebangs)
|
37
33
|
|
38
34
|
rule_sets = ::FastIgnore::RuleSetBuilder.from_args(
|
39
35
|
root: @root,
|
40
|
-
|
41
|
-
ignore_files: ignore_files,
|
42
|
-
gitignore: gitignore,
|
43
|
-
include_rules: include_rules,
|
44
|
-
include_files: include_files,
|
45
|
-
argv_rules: argv_rules
|
36
|
+
**rule_set_builder_args
|
46
37
|
)
|
47
38
|
|
48
39
|
@include_rule_sets, @ignore_rule_sets = rule_sets.partition(&:allow?)
|
49
40
|
@has_include_rule_sets = !@include_rule_sets.empty?
|
50
41
|
@relative = relative
|
42
|
+
|
43
|
+
freeze
|
51
44
|
end
|
52
45
|
|
53
46
|
def each(&block)
|
@@ -58,53 +51,55 @@ class FastIgnore
|
|
58
51
|
end
|
59
52
|
end
|
60
53
|
|
61
|
-
def allowed?(path)
|
62
|
-
|
63
|
-
|
54
|
+
def allowed?(path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
55
|
+
full_path = ::File.expand_path(path, @root)
|
56
|
+
return false unless full_path.start_with?(@root)
|
57
|
+
|
58
|
+
dir = ::File.stat(full_path).directory? # shortcut for exists? && directory?
|
64
59
|
|
65
60
|
return false if dir
|
66
|
-
|
67
|
-
|
61
|
+
|
62
|
+
relative_path = full_path.delete_prefix(@root)
|
63
|
+
|
64
|
+
return false unless @ignore_rule_sets.all? { |r| r.allowed_recursive?(relative_path, dir) }
|
65
|
+
return @include_rule_sets.all? { |r| r.allowed_recursive?(relative_path, dir) } unless @shebang_pattern
|
68
66
|
|
69
67
|
(@has_include_rule_sets &&
|
70
|
-
@include_rule_sets.all? { |r| r.allowed_unrecursive?(
|
71
|
-
match_shebang?(
|
72
|
-
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
68
|
+
@include_rule_sets.all? { |r| r.allowed_unrecursive?(relative_path, false) }) ||
|
69
|
+
match_shebang?(full_path, ::File.basename(relative_path))
|
70
|
+
rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ENOTDIR, ::Errno::ELOOP, ::Errno::ENAMETOOLONG
|
73
71
|
false
|
74
72
|
end
|
75
73
|
|
76
74
|
private
|
77
75
|
|
78
|
-
def
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
def each_allowed(path = @root_trailing_slash, &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
83
|
-
Dir.each_child(path) do |basename|
|
76
|
+
def each_allowed(full_path = @root, relative_path = '', &block) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
77
|
+
::Dir.each_child(full_path) do |basename|
|
84
78
|
begin
|
85
|
-
|
86
|
-
|
79
|
+
full_child = full_path + basename
|
80
|
+
relative_child = relative_path + basename
|
81
|
+
dir = ::File.directory?(full_child)
|
87
82
|
|
88
|
-
next unless @ignore_rule_sets.all? { |r| r.allowed_unrecursive?(
|
83
|
+
next unless @ignore_rule_sets.all? { |r| r.allowed_unrecursive?(relative_child, dir) }
|
89
84
|
|
90
85
|
if dir
|
91
|
-
next unless @shebang_pattern || @include_rule_sets.all? { |r| r.allowed_unrecursive?(
|
86
|
+
next unless @shebang_pattern || @include_rule_sets.all? { |r| r.allowed_unrecursive?(relative_child, dir) }
|
92
87
|
|
93
|
-
each_allowed("#{
|
88
|
+
each_allowed("#{full_child}/", "#{relative_child}/", &block)
|
94
89
|
else
|
95
90
|
if @shebang_pattern
|
96
91
|
unless (@has_include_rule_sets &&
|
97
|
-
@include_rule_sets.all? { |r| r.allowed_unrecursive?(
|
98
|
-
match_shebang?(
|
92
|
+
@include_rule_sets.all? { |r| r.allowed_unrecursive?(relative_child, dir) }) ||
|
93
|
+
match_shebang?(full_child, basename)
|
99
94
|
next
|
100
95
|
end
|
101
96
|
else
|
102
|
-
next unless @include_rule_sets.all? { |r| r.allowed_unrecursive?(
|
97
|
+
next unless @include_rule_sets.all? { |r| r.allowed_unrecursive?(relative_child, dir) }
|
103
98
|
end
|
104
99
|
|
105
|
-
yield
|
100
|
+
yield(@relative ? relative_child : full_child)
|
106
101
|
end
|
107
|
-
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
102
|
+
rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ENOTDIR, ::Errno::ELOOP, ::Errno::ENAMETOOLONG
|
108
103
|
nil
|
109
104
|
end
|
110
105
|
end
|
@@ -118,7 +113,7 @@ class FastIgnore
|
|
118
113
|
# i can't imagine a shebang being longer than 20 characters, lets multiply that by 10 just in case.
|
119
114
|
fragment = f.sysread(256)
|
120
115
|
f.close
|
121
|
-
rescue SystemCallError, EOFError
|
116
|
+
rescue ::SystemCallError, ::EOFError
|
122
117
|
return false
|
123
118
|
end
|
124
119
|
|
data/lib/fast_ignore/rule.rb
CHANGED
@@ -2,7 +2,11 @@
|
|
2
2
|
|
3
3
|
class FastIgnore
|
4
4
|
class Rule
|
5
|
-
FNMATCH_OPTIONS = (
|
5
|
+
# FNMATCH_OPTIONS = (
|
6
|
+
# ::File::FNM_DOTMATCH |
|
7
|
+
# ::File::FNM_PATHNAME |
|
8
|
+
# ::File::FNM_CASEFOLD
|
9
|
+
# ).freeze # = 14
|
6
10
|
|
7
11
|
attr_reader :negation
|
8
12
|
alias_method :negation?, :negation
|
@@ -15,6 +19,8 @@ class FastIgnore
|
|
15
19
|
@rule = rule
|
16
20
|
@dir_only = dir_only
|
17
21
|
@negation = negation
|
22
|
+
|
23
|
+
freeze
|
18
24
|
end
|
19
25
|
|
20
26
|
# :nocov:
|
@@ -11,74 +11,77 @@ class FastIgnore
|
|
11
11
|
|
12
12
|
# rule or nil
|
13
13
|
class << self
|
14
|
-
def new_rule(rule,
|
15
|
-
rule =
|
16
|
-
|
14
|
+
def new_rule(rule, rule_set:, allow: false, expand_path: false, file_root: nil) # rubocop:disable Metrics/MethodLength
|
15
|
+
rule = rule.dup
|
16
|
+
strip(rule)
|
17
|
+
dir_only = extract_dir_only(rule)
|
17
18
|
|
18
19
|
return if skip?(rule)
|
19
20
|
|
20
|
-
|
21
|
-
rule = expand_path(rule, root) if expand_path
|
21
|
+
negation = extract_negation(rule, allow)
|
22
22
|
|
23
|
-
|
23
|
+
expand_rule_path(rule, expand_path) if expand_path
|
24
|
+
anchored = anchored?(rule)
|
25
|
+
rule.delete_prefix!('/')
|
24
26
|
|
25
|
-
rule
|
27
|
+
rule.prepend("#{file_root}#{'**/' unless anchored}") if file_root || (not anchored)
|
28
|
+
|
29
|
+
rule.freeze
|
26
30
|
|
27
31
|
rule_set.append_rules(
|
28
32
|
anchored,
|
29
|
-
rules(rule, allow,
|
33
|
+
rules(rule, allow, dir_only, negation)
|
30
34
|
)
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
34
38
|
|
35
|
-
|
39
|
+
DOT = '.'
|
40
|
+
def rules(rule, allow, dir_only, negation)
|
36
41
|
rules = [::FastIgnore::Rule.new(rule, dir_only, negation)]
|
37
42
|
return rules unless allow
|
38
43
|
|
39
44
|
rules << ::FastIgnore::Rule.new("#{rule}/**/*", false, negation)
|
40
45
|
parent = File.dirname(rule)
|
41
|
-
while parent !=
|
42
|
-
rules << ::FastIgnore::Rule.new(parent, true, true)
|
46
|
+
while parent != DOT
|
47
|
+
rules << ::FastIgnore::Rule.new(parent.freeze, true, true)
|
43
48
|
parent = File.dirname(parent)
|
44
49
|
end
|
45
50
|
rules
|
46
51
|
end
|
47
52
|
|
48
53
|
def extract_negation(rule, allow)
|
49
|
-
return
|
54
|
+
return allow unless rule.start_with?('!')
|
55
|
+
|
56
|
+
rule.slice!(0)
|
50
57
|
|
51
|
-
|
58
|
+
!allow
|
52
59
|
end
|
53
60
|
|
54
61
|
def extract_dir_only(rule)
|
55
|
-
return
|
62
|
+
return false unless rule.end_with?('/')
|
63
|
+
|
64
|
+
rule.chop!
|
56
65
|
|
57
|
-
|
66
|
+
true
|
58
67
|
end
|
59
68
|
|
60
69
|
def strip(rule)
|
61
|
-
rule
|
62
|
-
rule
|
63
|
-
rule
|
70
|
+
rule.chomp!
|
71
|
+
rule.rstrip! unless rule.end_with?('\\ ')
|
64
72
|
end
|
65
73
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
[true, '/']
|
71
|
-
else
|
72
|
-
[false, '/**/']
|
73
|
-
end
|
74
|
+
def anchored?(rule)
|
75
|
+
rule.start_with?('/') ||
|
76
|
+
rule.end_with?('/**') ||
|
77
|
+
rule.include?('/**/')
|
74
78
|
end
|
75
79
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
rule
|
80
|
-
|
81
|
-
rule
|
80
|
+
EXPAND_PATH_RE = %r{^(?:[~/]|\.{1,2}/)}.freeze
|
81
|
+
def expand_rule_path(rule, root)
|
82
|
+
rule.replace(::File.expand_path(rule)) if rule.match?(EXPAND_PATH_RE)
|
83
|
+
rule.delete_prefix!(root)
|
84
|
+
rule.prepend('/') unless rule.start_with?('*') || rule.start_with?('/')
|
82
85
|
end
|
83
86
|
|
84
87
|
def skip?(rule)
|
data/lib/fast_ignore/rule_set.rb
CHANGED
@@ -6,18 +6,22 @@ class FastIgnore
|
|
6
6
|
attr_reader :allow
|
7
7
|
alias_method :allow?, :allow
|
8
8
|
|
9
|
-
def initialize(
|
9
|
+
def initialize(allow: false)
|
10
10
|
@dir_rules = []
|
11
11
|
@file_rules = []
|
12
|
-
@
|
13
|
-
|
12
|
+
@allowed_recursive = { '.' => true }
|
14
13
|
@any_not_anchored = false
|
15
14
|
@allow = allow
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
|
+
def freeze
|
18
|
+
@dir_rules.freeze
|
19
|
+
@file_rules.freeze
|
20
|
+
|
21
|
+
super
|
17
22
|
end
|
18
23
|
|
19
24
|
def allowed_recursive?(path, dir)
|
20
|
-
@allowed_recursive ||= { @project_root => true }
|
21
25
|
@allowed_recursive.fetch(path) do
|
22
26
|
@allowed_recursive[path] =
|
23
27
|
allowed_recursive?(::File.dirname(path), true) && allowed_unrecursive?(path, dir)
|
@@ -2,8 +2,15 @@
|
|
2
2
|
|
3
3
|
class FastIgnore
|
4
4
|
class RuleSetBuilder
|
5
|
+
# :nocov:
|
6
|
+
if ::FastIgnore::Backports.ruby_version_less_than?(2, 5)
|
7
|
+
require_relative 'backports/delete_prefix_suffix'
|
8
|
+
using ::FastIgnore::Backports::DeletePrefixSuffix
|
9
|
+
end
|
10
|
+
# :nocov:
|
11
|
+
|
5
12
|
def self.from_args( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
|
6
|
-
root
|
13
|
+
root:,
|
7
14
|
ignore_rules: nil,
|
8
15
|
ignore_files: nil,
|
9
16
|
gitignore: :auto,
|
@@ -12,13 +19,13 @@ class FastIgnore
|
|
12
19
|
argv_rules: nil
|
13
20
|
)
|
14
21
|
rule_sets = [
|
15
|
-
from_array(ignore_rules
|
22
|
+
from_array(ignore_rules),
|
16
23
|
*from_files(ignore_files, project_root: root),
|
17
|
-
from_array('.git'
|
18
|
-
from_gitignore_arg(gitignore,
|
19
|
-
from_array(include_rules,
|
24
|
+
from_array('.git'),
|
25
|
+
from_gitignore_arg(gitignore, project_root: root),
|
26
|
+
from_array(include_rules, allow: true),
|
20
27
|
*from_files(include_files, allow: true, project_root: root),
|
21
|
-
from_array(argv_rules,
|
28
|
+
from_array(argv_rules, allow: true, expand_path: root)
|
22
29
|
]
|
23
30
|
|
24
31
|
rule_sets.compact!
|
@@ -27,62 +34,58 @@ class FastIgnore
|
|
27
34
|
rule_sets
|
28
35
|
end
|
29
36
|
|
30
|
-
def self.from_file(filename, allow: false
|
31
|
-
filename = ::File.expand_path(filename)
|
32
|
-
|
33
|
-
|
37
|
+
def self.from_file(filename, project_root:, allow: false)
|
38
|
+
filename = ::File.expand_path(filename, project_root)
|
39
|
+
raise FastIgnore::Error, "#{filename} is not within #{project_root}" unless filename.start_with?(project_root)
|
40
|
+
|
41
|
+
file_root = "#{::File.dirname(filename)}/".delete_prefix(project_root)
|
42
|
+
rule_set = ::FastIgnore::RuleSet.new(allow: allow)
|
34
43
|
|
35
44
|
::IO.foreach(filename) do |rule_string|
|
36
|
-
parse_rules(rule_string, allow: allow, rule_set: rule_set,
|
45
|
+
parse_rules(rule_string, allow: allow, rule_set: rule_set, file_root: file_root)
|
37
46
|
end
|
38
47
|
|
39
|
-
rule_set
|
48
|
+
rule_set.freeze
|
40
49
|
end
|
41
50
|
|
42
|
-
def self.from_files(files, allow: false
|
51
|
+
def self.from_files(files, project_root:, allow: false)
|
43
52
|
Array(files).map do |file|
|
44
53
|
from_file(file, allow: allow, project_root: project_root)
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
|
-
def self.from_gitignore_arg(gitignore,
|
49
|
-
default_path = ::File.join(
|
57
|
+
def self.from_gitignore_arg(gitignore, project_root:)
|
58
|
+
default_path = ::File.join(project_root, '.gitignore')
|
50
59
|
case gitignore
|
51
60
|
when :auto
|
52
|
-
from_file(default_path, project_root:
|
61
|
+
from_file(default_path, project_root: project_root) if ::File.exist?(default_path)
|
53
62
|
when true
|
54
|
-
from_file(default_path, project_root:
|
55
|
-
when false
|
56
|
-
nil
|
57
|
-
else
|
58
|
-
warn 'Deprecation warning! supplying gitignore file path directly is deprecated. '\
|
59
|
-
'Please use gitignore: false and add your path to the ignore_files array'
|
60
|
-
from_file(gitignore, project_root: root)
|
63
|
+
from_file(default_path, project_root: project_root)
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
|
-
def self.from_array(rules, allow: false, expand_path: false
|
67
|
+
def self.from_array(rules, allow: false, expand_path: false)
|
65
68
|
rules = Array(rules)
|
66
69
|
return if rules.empty?
|
67
70
|
|
68
|
-
rule_set = ::FastIgnore::RuleSet.new(
|
71
|
+
rule_set = ::FastIgnore::RuleSet.new(allow: allow)
|
69
72
|
|
70
73
|
rules.each do |rule_string|
|
71
74
|
rule_string.to_s.each_line do |rule_line|
|
72
|
-
parse_rules(rule_line, rule_set: rule_set, allow: allow,
|
75
|
+
parse_rules(rule_line, rule_set: rule_set, allow: allow, expand_path: expand_path)
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
76
|
-
rule_set
|
79
|
+
rule_set.freeze
|
77
80
|
end
|
78
81
|
|
79
|
-
def self.parse_rules(rule_line, rule_set:, allow: false,
|
82
|
+
def self.parse_rules(rule_line, rule_set:, allow: false, expand_path: false, file_root: nil)
|
80
83
|
::FastIgnore::RuleParser.new_rule(
|
81
84
|
rule_line,
|
82
85
|
rule_set: rule_set,
|
83
86
|
allow: allow,
|
84
|
-
|
85
|
-
|
87
|
+
expand_path: expand_path,
|
88
|
+
file_root: file_root
|
86
89
|
)
|
87
90
|
end
|
88
91
|
end
|
data/lib/fast_ignore/version.rb
CHANGED
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.9.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: 2020-04-
|
11
|
+
date: 2020-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|