fast_ignore 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/fast_ignore/rule.rb +4 -0
- data/lib/fast_ignore/rule_set.rb +12 -15
- data/lib/fast_ignore/rule_set_builder.rb +1 -9
- data/lib/fast_ignore/version.rb +1 -1
- data/lib/fast_ignore.rb +25 -23
- 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: 35a905f9dd8c28df7b46d6c0c61ad1fcaf44a9566c19b704a88584668f49ba20
|
4
|
+
data.tar.gz: 620917002cd9696bb5787819675034d6b5269d70812f0e5247523b10091d37b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6406dd9e6998fb9a3345981239e7fa0046f1356852a599f2c347d4b7bec4654069ac5704351c3079ce79c0965925a601dbcf56990ac6850aefef5f3a109793fa
|
7
|
+
data.tar.gz: 83a7aacfd25b3350a4100d6247c683f6b4f1754c6311d9b6064631e5033890ea2fcc0c8dd5b5757f8f0e9a39af55cfc3f7560918813e69ab6e9139734abc4fa1
|
data/CHANGELOG.md
CHANGED
data/lib/fast_ignore/rule.rb
CHANGED
data/lib/fast_ignore/rule_set.rb
CHANGED
@@ -10,31 +10,29 @@ class FastIgnore
|
|
10
10
|
@rules = []
|
11
11
|
@non_dir_only_rules = []
|
12
12
|
@project_root = project_root
|
13
|
-
|
14
|
-
@allowed_recursive = { @project_root => true }
|
13
|
+
|
15
14
|
@any_not_anchored = false
|
16
15
|
@empty = true
|
17
16
|
@allow = allow
|
18
17
|
end
|
19
18
|
|
20
|
-
def allowed_unrecursive?(path, dir)
|
21
|
-
@allowed_unrecursive.fetch(path) do
|
22
|
-
(dir ? @rules : @non_dir_only_rules).reverse_each do |rule|
|
23
|
-
# 14 = Rule::FNMATCH_OPTIONS
|
24
|
-
return @allowed_unrecursive[path] = rule.negation? if ::File.fnmatch?(rule.rule, path, 14)
|
25
|
-
end
|
26
|
-
|
27
|
-
@allowed_unrecursive[path] = default?(dir)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
19
|
def allowed_recursive?(path, dir)
|
20
|
+
@allowed_recursive ||= { @project_root => true }
|
32
21
|
@allowed_recursive.fetch(path) do
|
33
22
|
@allowed_recursive[path] =
|
34
23
|
allowed_recursive?(::File.dirname(path), true) && allowed_unrecursive?(path, dir)
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
27
|
+
def allowed_unrecursive?(path, dir)
|
28
|
+
(dir ? @rules : @non_dir_only_rules).reverse_each do |rule|
|
29
|
+
# 14 = Rule::FNMATCH_OPTIONS
|
30
|
+
return rule.negation? if ::File.fnmatch?(rule.rule, path, 14)
|
31
|
+
end
|
32
|
+
|
33
|
+
default?(dir)
|
34
|
+
end
|
35
|
+
|
38
36
|
def parse_rules(rule_line, root: @root, expand_path: false)
|
39
37
|
::FastIgnore::RuleParser.new_rule(rule_line, rule_set: self, allow: @allow, root: root, expand_path: expand_path)
|
40
38
|
end
|
@@ -49,8 +47,7 @@ class FastIgnore
|
|
49
47
|
end
|
50
48
|
|
51
49
|
def clear_cache
|
52
|
-
@
|
53
|
-
@allowed_recursive = { @project_root => true }
|
50
|
+
@allowed_recursive = nil
|
54
51
|
end
|
55
52
|
|
56
53
|
private
|
@@ -4,7 +4,7 @@ require_relative 'rule_set'
|
|
4
4
|
|
5
5
|
class FastIgnore
|
6
6
|
class RuleSetBuilder
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :rule_set
|
8
8
|
|
9
9
|
def initialize(root:, allow: false)
|
10
10
|
@rule_set = RuleSet.new(project_root: root, allow: allow)
|
@@ -33,13 +33,5 @@ class FastIgnore
|
|
33
33
|
|
34
34
|
@rule_set.clear_cache
|
35
35
|
end
|
36
|
-
|
37
|
-
def allowed_unrecursive?(path, dir)
|
38
|
-
@rule_set.allowed_unrecursive?(path, dir)
|
39
|
-
end
|
40
|
-
|
41
|
-
def allowed_recursive?(path, dir)
|
42
|
-
@rule_set.allowed_recursive?(path, dir)
|
43
|
-
end
|
44
36
|
end
|
45
37
|
end
|
data/lib/fast_ignore/version.rb
CHANGED
data/lib/fast_ignore.rb
CHANGED
@@ -15,7 +15,7 @@ class FastIgnore
|
|
15
15
|
using ::FastIgnore::Backports::DirEachChild
|
16
16
|
end
|
17
17
|
|
18
|
-
def initialize( # rubocop:disable Metrics/ParameterLists
|
18
|
+
def initialize( # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength, Metrics/AbcSize
|
19
19
|
relative: false,
|
20
20
|
root: ::Dir.pwd,
|
21
21
|
ignore_rules: nil,
|
@@ -24,24 +24,27 @@ class FastIgnore
|
|
24
24
|
include_rules: nil,
|
25
25
|
include_files: nil
|
26
26
|
)
|
27
|
-
@
|
28
|
-
@
|
29
|
-
|
30
|
-
|
27
|
+
@root = root.delete_suffix('/')
|
28
|
+
@root_trailing_slash = "#{@root}/"
|
29
|
+
ignore = ::FastIgnore::RuleSetBuilder.new(root: @root)
|
30
|
+
only = ::FastIgnore::RuleSetBuilder.new(allow: true, root: @root)
|
31
|
+
only.add_files(Array(include_files))
|
32
|
+
only.add_rules(Array(include_rules), expand_path: true)
|
33
|
+
@only = only.rule_set
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
ignore.add_rules(['.git'])
|
36
|
+
ignore.add_files([gitignore]) if gitignore && ::File.exist?(gitignore)
|
37
|
+
ignore.add_files(Array(ignore_files))
|
38
|
+
ignore.add_rules(Array(ignore_rules))
|
39
|
+
@ignore = ignore.rule_set
|
36
40
|
@relative = relative
|
37
|
-
@root = root
|
38
41
|
end
|
39
42
|
|
40
43
|
def each(&block)
|
41
44
|
if block_given?
|
42
|
-
all_allowed
|
45
|
+
all_allowed(&block)
|
43
46
|
else
|
44
|
-
all_allowed
|
47
|
+
enum_for(:all_allowed)
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -52,33 +55,32 @@ class FastIgnore
|
|
52
55
|
end
|
53
56
|
|
54
57
|
def all_allowed
|
55
|
-
|
56
|
-
find_children(@root) do |path, dir|
|
58
|
+
find_children(@root_trailing_slash) do |path, dir|
|
57
59
|
next false unless @ignore.allowed_unrecursive?(path, dir)
|
58
60
|
next false unless @only.allowed_unrecursive?(path, dir)
|
59
61
|
next true if dir
|
60
|
-
next false unless ::File.readable?(path)
|
61
62
|
|
62
|
-
|
63
|
+
yield prepare_path(path)
|
63
64
|
|
64
65
|
false
|
65
66
|
end
|
66
|
-
allowed
|
67
67
|
end
|
68
68
|
|
69
69
|
private
|
70
70
|
|
71
71
|
def prepare_path(path)
|
72
|
-
@relative ? path.delete_prefix(
|
72
|
+
@relative ? path.delete_prefix(@root_trailing_slash) : path
|
73
73
|
end
|
74
74
|
|
75
|
-
def find_children(path, &block)
|
75
|
+
def find_children(path, &block) # rubocop:disable Metrics/MethodLength
|
76
76
|
Dir.each_child(path) do |child|
|
77
77
|
begin
|
78
|
-
child =
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
child = path + child
|
79
|
+
stat = ::File.stat(child)
|
80
|
+
next unless stat.readable?
|
81
|
+
|
82
|
+
look_at_children = block.call child, stat.directory?
|
83
|
+
find_children("#{child}/", &block) if look_at_children
|
82
84
|
rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
|
83
85
|
nil
|
84
86
|
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.5.
|
4
|
+
version: 0.5.2
|
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-02-
|
11
|
+
date: 2020-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|