fast_ignore 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: e04a993446a5adf5f369e13852771d66abd503187742c80898e811124529a866
4
- data.tar.gz: b2bd89f8e2430fa28b7c9930f10eadabafd81dfd49bc89daf8531a0ca2612351
2
+ SHA1:
3
+ metadata.gz: dad6489c13a9f963a02bff55376b8ff3f6b933d7
4
+ data.tar.gz: '030182407da00aba178d8d9160b8a9cd08d71b87'
5
5
  SHA512:
6
- metadata.gz: 7c575e2da6d571adf99e9d969627c52745e8d6c4708405890dd183a8a6ebb5e92456a4c51dc0a39f88ede5d9d819b64f9feeed2f3c0db8b426a946ec12df169b
7
- data.tar.gz: 6befd0197a2f56029937bf67956c31aa1d2084559fcef44ca6b9ecec75a4a44cf49df1407f07555f4079dbed53d261a4a322bdcd171b692ef6995e684c6a3edd
6
+ metadata.gz: e13027962d2acbc50757129ed768325c18eaa2b12e937d4c2a1f1c51e6af21420c492acdc10d0c39a793c674918744f0a18332d9a63001b723bee38908524c7b
7
+ data.tar.gz: 1fb547b9b47186b60d20d4006ecc1662e44ea9259269d219a9b47c7e45591684479a77de80fd7e79a706be0c8747fd7c2cdbb300101f424dc6967e99d914ea2b
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
  *.gem
13
+ Gemfile.lock
data/.rubocop.yml CHANGED
@@ -37,11 +37,11 @@ AllCops:
37
37
  # end
38
38
 
39
39
  # to match our preference for consistent indentation
40
- Layout/AlignHash:
40
+ Layout/HashAlignment:
41
41
  EnforcedLastArgumentHashStyle: always_ignore
42
42
 
43
43
  # to match our preference for consistent indentation
44
- Layout/AlignParameters:
44
+ Layout/ParameterAlignment:
45
45
  EnforcedStyle: with_fixed_indentation
46
46
 
47
47
  # to match our preference for consistent indentation
@@ -69,15 +69,15 @@ Layout/FirstHashElementLineBreak:
69
69
  Enabled: true
70
70
 
71
71
  # to match our preference for consistent indentation
72
- Layout/IndentFirstArgument:
72
+ Layout/FirstArgumentIndentation:
73
73
  EnforcedStyle: consistent
74
74
 
75
75
  # to match our preference for consistent indentation
76
- Layout/IndentFirstArrayElement:
76
+ Layout/FirstArrayElementIndentation:
77
77
  EnforcedStyle: consistent
78
78
 
79
79
  # to match our preference for consistent indentation
80
- Layout/IndentFirstHashElement:
80
+ Layout/FirstHashElementIndentation:
81
81
  EnforcedStyle: consistent
82
82
 
83
83
  # to match our preference for consistent indentation
@@ -117,6 +117,12 @@ Metrics/BlockLength:
117
117
  Metrics/LineLength:
118
118
  Max: 120
119
119
 
120
+ Metrics/CyclomaticComplexity:
121
+ Enabled: false
122
+
123
+ Metrics/PerceivedComplexity:
124
+ Enabled: false
125
+
120
126
  RSpec:
121
127
  Enabled: true
122
128
  Include:
data/.travis.yml CHANGED
@@ -7,4 +7,5 @@ rvm:
7
7
  - 2.4
8
8
  - 2.5
9
9
  - 2.6
10
+ - 2.7
10
11
  before_install: gem install bundler -v 1.17.3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v0.5.0
2
+ - remove deprecated `:rules` and `:files` arguments
3
+ - ! is now evaluated in sequence for include_rules
4
+ - it's a big refactor, sorry if i broke something
5
+ - some performance improvements
6
+
1
7
  # v0.4.1
2
8
  - oops i did a regexp wrong
3
9
 
data/README.md CHANGED
@@ -87,12 +87,9 @@ foo
87
87
  # a line ending in a slash will will include any files in any directories named foo
88
88
  # but not any files named foo
89
89
  foo/
90
- # negated rules are slightly different from gitignore
91
- # in that they're evaluated after all the other the matching files rather than
92
- # in sequence with other rules
93
90
  fo*
94
91
  !foe
95
- # otherwise this format deals with *'s and ?'s and etc as you'd expect from gitignore.
92
+ # otherwise this format deals with !'s, *'s and ?'s and etc as you'd expect from gitignore.
96
93
  ```
97
94
 
98
95
  These can be passed either as files or as an array or string rules
data/fast_ignore.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  end
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_development_dependency 'bundler', '~> 1.17'
30
+ spec.add_development_dependency 'bundler', '>= 1.17'
31
31
  spec.add_development_dependency 'pry', '~> 0'
32
32
  spec.add_development_dependency 'rake', '~> 10.0'
33
33
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is a backport of ruby 2.5's each_child method
4
+ class FastIgnore
5
+ module Backports
6
+ module DirEachChild
7
+ refine ::Dir.singleton_class do
8
+ def each_child(path, &block)
9
+ Dir.entries(path).each do |entry|
10
+ next if entry == '.' || entry == '..'
11
+
12
+ block.call entry
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -2,111 +2,19 @@
2
2
 
3
3
  class FastIgnore
4
4
  class Rule
5
- unless ::RUBY_VERSION >= '2.5'
6
- require_relative 'backports/delete_prefix_suffix'
7
- using ::FastIgnore::Backports::DeletePrefixSuffix
8
- end
9
-
10
- unless ::RUBY_VERSION >= '2.4'
11
- require_relative 'backports/match'
12
- using ::FastIgnore::Backports::Match
13
- end
5
+ FNMATCH_OPTIONS = (::File::FNM_DOTMATCH | ::File::FNM_PATHNAME | ::File::FNM_CASEFOLD).freeze # = 14
14
6
 
15
- FNMATCH_OPTIONS = (::File::FNM_DOTMATCH | ::File::FNM_PATHNAME | ::File::FNM_CASEFOLD).freeze
7
+ attr_reader :negation
8
+ alias_method :negation?, :negation
9
+ attr_reader :dir_only
10
+ alias_method :dir_only?, :dir_only
16
11
 
17
- attr_reader :rule, :glob_prefix
12
+ attr_reader :rule
18
13
 
19
- def initialize(rule, root:, expand_path: false)
14
+ def initialize(rule, dir_only, negation)
20
15
  @rule = rule
21
- strip!
22
- extract_dir_only
23
- expand_path(root) if expand_path
24
- return if skip?
25
-
26
- extract_negation
27
-
28
- @rule = "#{root}#{prefix}#{@rule}"
29
- end
30
-
31
- def negation?
32
- @negation
33
- end
34
-
35
- def invert
36
- @negation = !@negation
37
- end
38
-
39
- def glob_pattern
40
- @glob_pattern ||= if @dir_only
41
- "#{@rule}/**/*"
42
- else
43
- [@rule, "#{@rule}/**/*"]
44
- end
45
- end
46
-
47
- def globbable?
48
- !@rule.match?(%r{/\*\*/.*[^*/]})
49
- end
50
-
51
- def extract_negation
52
- @negation = false
53
- return unless @rule.start_with?('!')
54
-
55
- @rule = @rule[1..-1]
56
- @negation = true
57
- end
58
-
59
- def extract_dir_only
60
- @dir_only = false
61
- return unless @rule.end_with?('/')
62
-
63
- @rule = @rule[0..-2]
64
- @dir_only = true
65
- end
66
-
67
- def dir_only?
68
- @dir_only
69
- end
70
-
71
- def match?(path)
72
- ::File.fnmatch?(@rule, path, ::FastIgnore::Rule::FNMATCH_OPTIONS)
73
- end
74
-
75
- def empty?
76
- return @empty if defined?(@empty)
77
-
78
- @empty ||= @rule.empty?
79
- end
80
-
81
- def comment?
82
- return @comment if defined?(@comment)
83
-
84
- @comment ||= @rule.start_with?('#')
85
- end
86
-
87
- def skip?
88
- empty? || comment?
89
- end
90
-
91
- private
92
-
93
- def expand_path(root)
94
- @rule = ::File.expand_path(@rule).delete_prefix(root) if @rule.match?(%r{^(?:[~/]|\.{1,2}/)})
95
- end
96
-
97
- def prefix
98
- @prefix ||= if @rule.start_with?('/')
99
- ''
100
- elsif @rule.end_with?('/**') || @rule.include?('/**/')
101
- '/'
102
- else
103
- '/**/'
104
- end
105
- end
106
-
107
- def strip!
108
- @rule = @rule.chomp
109
- @rule = @rule.rstrip unless @rule.end_with?('\\ ')
16
+ @dir_only = dir_only
17
+ @negation = negation
110
18
  end
111
19
  end
112
20
  end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rule'
4
+
5
+ class FastIgnore
6
+ class RuleParser
7
+ unless ::RUBY_VERSION >= '2.4'
8
+ require_relative 'backports/match'
9
+ using ::FastIgnore::Backports::Match
10
+ end
11
+
12
+ unless ::RUBY_VERSION >= '2.5'
13
+ require_relative 'backports/delete_prefix_suffix'
14
+ using ::FastIgnore::Backports::DeletePrefixSuffix
15
+ end
16
+
17
+ # rule or nil
18
+ class << self
19
+ def new_rule(rule, root:, rule_set:, allow: false, expand_path: false) # rubocop:disable Metrics/MethodLength
20
+ rule = strip(rule)
21
+ rule, dir_only = extract_dir_only(rule)
22
+ rule = expand_path(rule, root) if expand_path
23
+
24
+ return if skip?(rule)
25
+
26
+ rule, negation = extract_negation(rule, allow)
27
+
28
+ anchored, prefix = prefix(rule)
29
+
30
+ rule = "#{root}#{prefix}#{rule}"
31
+
32
+ rule_set.append_rules(
33
+ anchored,
34
+ rules(rule, allow, root, dir_only, negation)
35
+ )
36
+ end
37
+
38
+ private
39
+
40
+ def rules(rule, allow, root, dir_only, negation)
41
+ rules = [::FastIgnore::Rule.new(rule, dir_only, negation)]
42
+ return rules unless allow
43
+
44
+ rules << ::FastIgnore::Rule.new("#{rule}/**/*", false, negation)
45
+ parent = File.dirname(rule)
46
+ while parent != root
47
+ rules << ::FastIgnore::Rule.new(parent, true, true)
48
+ parent = File.dirname(parent)
49
+ end
50
+ rules
51
+ end
52
+
53
+ def extract_negation(rule, allow)
54
+ return [rule, allow] unless rule.start_with?('!')
55
+
56
+ [rule[1..-1], !allow]
57
+ end
58
+
59
+ def extract_dir_only(rule)
60
+ return [rule, false] unless rule.end_with?('/')
61
+
62
+ [rule[0..-2], true]
63
+ end
64
+
65
+ def strip(rule)
66
+ rule = rule.chomp
67
+ rule = rule.rstrip unless rule.end_with?('\\ ')
68
+ rule
69
+ end
70
+
71
+ def prefix(rule)
72
+ if rule.start_with?('/')
73
+ [true, '']
74
+ elsif rule.end_with?('/**') || rule.include?('/**/')
75
+ [true, '/']
76
+ else
77
+ [false, '/**/']
78
+ end
79
+ end
80
+
81
+ def expand_path(rule, root)
82
+ if rule.match?(%r{^(?:[~/]|\.{1,2}/)})
83
+ ::File.expand_path(rule).delete_prefix(root)
84
+ else
85
+ rule
86
+ end
87
+ end
88
+
89
+ def skip?(rule)
90
+ empty?(rule) || comment?(rule)
91
+ end
92
+
93
+ def empty?(rule)
94
+ rule.empty?
95
+ end
96
+
97
+ def comment?(rule)
98
+ rule.start_with?('#')
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rule_parser'
4
+
5
+ class FastIgnore
6
+ class RuleSet
7
+ attr_reader :rules
8
+
9
+ def initialize(project_root: Dir.pwd, allow: false)
10
+ @rules = []
11
+ @non_dir_only_rules = []
12
+ @allowed_unrecursive = {}
13
+ @allowed_recursive = {}
14
+ @project_root = project_root
15
+ @any_not_anchored = false
16
+ @empty = true
17
+ @allow = allow
18
+ end
19
+
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
+ def allowed_recursive?(path, dir)
32
+ return true if path == @project_root
33
+
34
+ @allowed_recursive.fetch(path) do
35
+ @allowed_recursive[path] =
36
+ allowed_recursive?(path, true) && allowed_unrecusrive?(path, dir)
37
+ end
38
+ end
39
+
40
+ def parse_rules(rule_line, root: @root, expand_path: false)
41
+ ::FastIgnore::RuleParser.new_rule(rule_line, rule_set: self, allow: @allow, root: root, expand_path: expand_path)
42
+ end
43
+
44
+ def append_rules(anchored, rules)
45
+ rules.each do |rule|
46
+ @empty = false
47
+ @rules << rule
48
+ @non_dir_only_rules << rule unless rule.dir_only?
49
+ @any_not_anchored ||= !anchored
50
+ end
51
+ end
52
+
53
+ def clear_cache
54
+ @allowed_unrecursive = {}
55
+ @allowed_recursive = {}
56
+ end
57
+
58
+ private
59
+
60
+ def default?(dir)
61
+ return true unless @allow
62
+ return true if @empty
63
+ return false unless dir
64
+ return true if @any_not_anchored
65
+
66
+ false
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'rule_set'
4
+
5
+ class FastIgnore
6
+ class RuleSetBuilder
7
+ attr_reader :rules
8
+
9
+ def initialize(root:, allow: false)
10
+ @rule_set = RuleSet.new(project_root: root, allow: allow)
11
+ @root = root
12
+ @allow = allow
13
+ end
14
+
15
+ def add_rules(rules, expand_path: false)
16
+ rules.each do |rule_string|
17
+ rule_string.each_line do |rule_line|
18
+ @rule_set.parse_rules(rule_line, root: @root, expand_path: expand_path)
19
+ end
20
+ end
21
+
22
+ @rule_set.clear_cache
23
+ end
24
+
25
+ def add_files(files)
26
+ files.each do |filename|
27
+ filename = ::File.expand_path(filename)
28
+ root = ::File.dirname(filename)
29
+ ::IO.foreach(filename) do |rule_string|
30
+ @rule_set.parse_rules(rule_string, root: root)
31
+ end
32
+ end
33
+
34
+ @rule_set.clear_cache
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
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FastIgnore
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/fast_ignore.rb CHANGED
@@ -1,13 +1,8 @@
1
1
  # frozen_string_literal: true
2
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'
3
+ require_relative './fast_ignore/rule_set_builder'
7
4
 
8
- require 'find'
9
-
10
- class FastIgnore # rubocop:disable Metrics/ClassLength
5
+ class FastIgnore
11
6
  include ::Enumerable
12
7
 
13
8
  unless ::RUBY_VERSION >= '2.5'
@@ -15,159 +10,78 @@ class FastIgnore # rubocop:disable Metrics/ClassLength
15
10
  using ::FastIgnore::Backports::DeletePrefixSuffix
16
11
  end
17
12
 
18
- attr_reader :relative
19
- alias_method :relative?, :relative
20
- attr_reader :root
13
+ unless ::RUBY_VERSION >= '2.5'
14
+ require_relative 'fast_ignore/backports/dir_each_child'
15
+ using ::FastIgnore::Backports::DirEachChild
16
+ end
21
17
 
22
18
  def initialize( # rubocop:disable Metrics/ParameterLists
23
19
  relative: false,
24
20
  root: ::Dir.pwd,
25
- rules: nil,
26
- ignore_rules: rules,
27
- files: nil,
28
- ignore_files: files,
21
+ ignore_rules: nil,
22
+ ignore_files: nil,
29
23
  gitignore: ::File.join(root, '.gitignore'),
30
24
  include_rules: nil,
31
25
  include_files: nil
32
26
  )
33
- if rules || files
34
- warn <<~WARNING
35
- \e[33mFastIgnore.new `:rules` and `:files` keyword arguments are deprecated.
36
- Please use `:ignore_rules` and `:ignore_files` instead.\e[0m
37
- WARNING
38
- end
39
- prepare_include_rules(include_rules, include_files)
40
- prepare_ignore_rules(ignore_rules, ignore_files, gitignore)
27
+ @ignore = ::FastIgnore::RuleSetBuilder.new(root: root)
28
+ @only = ::FastIgnore::RuleSetBuilder.new(allow: true, root: root)
29
+ @only.add_files(Array(include_files))
30
+ @only.add_rules(Array(include_rules), expand_path: true)
31
+
32
+ @ignore.add_rules(['.git'])
33
+ @ignore.add_files([gitignore]) if gitignore && ::File.exist?(gitignore)
34
+ @ignore.add_files(Array(ignore_files))
35
+ @ignore.add_rules(Array(ignore_rules))
41
36
  @relative = relative
42
37
  @root = root
43
38
  end
44
39
 
45
- def prepare_ignore_rules(ignore_rules, ignore_files, gitignore)
46
- @ignore_rules += ::FastIgnore::RuleList.new(*Array(ignore_rules)).to_a
47
- Array(ignore_files).reverse_each do |file|
48
- @ignore_rules += ::FastIgnore::FileRuleList.new(file).to_a
49
- end
50
-
51
- @ignore_rules += ::FastIgnore::GitignoreRuleList.new(gitignore).to_a if gitignore
52
- end
53
-
54
- def prepare_include_rules(include_rules, include_files)
55
- include_rules = ::FastIgnore::RuleList.new(*Array(include_rules), expand_path: true).to_a
56
- Array(include_files).reverse_each do |file|
57
- include_rules += ::FastIgnore::FileRuleList.new(file).to_a
58
- end
59
-
60
- @include_rules = include_rules.reject(&:negation?)
61
- @ignore_rules = include_rules.select(&:negation?).each(&:invert)
62
- end
63
-
64
40
  def each(&block)
65
41
  if block_given?
66
- enumerator.each(&block)
42
+ all_allowed.each(&block)
67
43
  else
68
- enumerator
44
+ all_allowed.each
69
45
  end
70
46
  end
71
47
 
72
48
  def allowed?(path)
73
- allowed_expanded?(::File.expand_path(path))
49
+ path = ::File.expand_path(path)
50
+ dir = ::File.directory?(path)
51
+ @ignore.allowed_recursive?(path, dir) && @only.allowed_recursive?(path, dir)
74
52
  end
75
53
 
76
- private
54
+ def all_allowed
55
+ allowed = []
56
+ find_children(@root) do |path, dir|
57
+ next false unless @ignore.allowed_unrecursive?(path, dir)
58
+ next false unless @only.allowed_unrecursive?(path, dir)
59
+ next true if dir
60
+ next false unless ::File.readable?(path)
77
61
 
78
- def enumerator
79
- if !@include_rules.empty? && @include_rules.all?(&:globbable?)
80
- glob_enumerator
81
- else
82
- find_enumerator
83
- end
84
- end
62
+ allowed << prepare_path(path)
85
63
 
86
- def allowed_expanded?(path, dir = ::File.directory?(path))
87
- not_excluded_recursive?(path, dir) && not_ignored_recursive?(path, dir)
88
- end
89
-
90
- def glob_enumerator # rubocop:disable Metrics/MethodLength
91
- seen = {}
92
- ::Enumerator.new do |yielder|
93
- ::Dir.glob(@include_rules.flat_map(&:glob_pattern), ::FastIgnore::Rule::FNMATCH_OPTIONS) do |path|
94
- next if seen[path]
95
-
96
- seen[path] = true
97
- next if ::File.directory?(path)
98
- next unless ::File.readable?(path)
99
- next unless not_ignored_recursive?(path, false)
100
-
101
- path = path.delete_prefix("#{root}/") if @relative
102
-
103
- yielder << path
104
- end
64
+ false
105
65
  end
66
+ allowed
106
67
  end
107
68
 
108
- def find_enumerator # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
109
- ::Enumerator.new do |yielder|
110
- ::Find.find(root) do |path|
111
- next if path == root
112
- next unless ::File.readable?(path)
113
-
114
- dir = ::File.directory?(path)
115
- next ::Find.prune unless not_ignored?(path, dir)
116
- next unless not_excluded_recursive?(path, dir)
117
- next if dir
118
-
119
- path = path.delete_prefix("#{root}/") if @relative
120
-
121
- yielder << path
122
- end
123
- end
124
- end
69
+ private
125
70
 
126
- def not_ignored_recursive?(path, dir = ::File.directory?(path))
127
- @not_ignored ||= {}
128
- @not_ignored.fetch(path) do
129
- @not_ignored[path] = if path == root
130
- true
131
- else
132
- not_ignored_recursive?(::File.dirname(path), true) && not_ignored?(path, dir)
133
- end
134
- end
71
+ def prepare_path(path)
72
+ @relative ? path.delete_prefix("#{@root}/") : path
135
73
  end
136
74
 
137
- def not_excluded_recursive?(path, dir = ::File.directory?(path))
138
- return true if @include_rules.empty?
139
-
140
- @not_excluded ||= {}
141
- @not_excluded.fetch(path) do
142
- @not_excluded[path] = if path == root
143
- false
144
- else
145
- not_excluded_recursive?(::File.dirname(path), true) || not_excluded?(path, dir)
75
+ def find_children(path, &block)
76
+ Dir.each_child(path) do |child|
77
+ begin
78
+ child = ::File.join(path, child)
79
+ dir = ::File.directory?(child)
80
+ look_at_children = block.call child, dir
81
+ find_children(child, &block) if look_at_children
82
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
83
+ nil
146
84
  end
147
85
  end
148
86
  end
149
-
150
- def non_dir_ignore_rules
151
- @non_dir_ignore_rules ||= @ignore_rules.reject(&:dir_only?)
152
- end
153
-
154
- def non_dir_include_rules
155
- @non_dir_include_rules ||= @include_rules.reject(&:dir_only?)
156
- end
157
-
158
- def not_excluded?(path, dir)
159
- return true if @include_rules.empty?
160
-
161
- (dir ? @include_rules : non_dir_include_rules).find do |rule|
162
- rule.match?(path)
163
- end
164
- end
165
-
166
- def not_ignored?(path, dir)
167
- (dir ? @ignore_rules : non_dir_ignore_rules).each do |rule|
168
- return rule.negation? if rule.match?(path)
169
- end
170
-
171
- true
172
- end
173
87
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_ignore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.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-10-06 00:00:00.000000000 Z
11
+ date: 2020-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.17'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.17'
27
27
  - !ruby/object:Gem::Dependency
@@ -107,7 +107,6 @@ files:
107
107
  - ".travis.yml"
108
108
  - CHANGELOG.md
109
109
  - Gemfile
110
- - Gemfile.lock
111
110
  - LICENSE.txt
112
111
  - README.md
113
112
  - Rakefile
@@ -117,11 +116,12 @@ files:
117
116
  - fast_ignore.gemspec
118
117
  - lib/fast_ignore.rb
119
118
  - lib/fast_ignore/backports/delete_prefix_suffix.rb
119
+ - lib/fast_ignore/backports/dir_each_child.rb
120
120
  - lib/fast_ignore/backports/match.rb
121
- - lib/fast_ignore/file_rule_list.rb
122
- - lib/fast_ignore/gitignore_rule_list.rb
123
121
  - lib/fast_ignore/rule.rb
124
- - lib/fast_ignore/rule_list.rb
122
+ - lib/fast_ignore/rule_parser.rb
123
+ - lib/fast_ignore/rule_set.rb
124
+ - lib/fast_ignore/rule_set_builder.rb
125
125
  - lib/fast_ignore/version.rb
126
126
  homepage: https://github.com/robotdana/fast_ignore
127
127
  licenses:
@@ -145,7 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.0.3
148
+ rubyforge_project:
149
+ rubygems_version: 2.5.2.1
149
150
  signing_key:
150
151
  specification_version: 4
151
152
  summary: Parse gitignore files, quickly
data/Gemfile.lock DELETED
@@ -1,60 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- fast_ignore (0.4.1)
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.3)
13
- method_source (0.9.2)
14
- parallel (1.17.0)
15
- parser (2.6.3.0)
16
- ast (~> 2.4.0)
17
- pry (0.12.2)
18
- coderay (~> 1.1.0)
19
- method_source (~> 0.9.0)
20
- rainbow (3.0.0)
21
- rake (10.5.0)
22
- rspec (3.8.0)
23
- rspec-core (~> 3.8.0)
24
- rspec-expectations (~> 3.8.0)
25
- rspec-mocks (~> 3.8.0)
26
- rspec-core (3.8.2)
27
- rspec-support (~> 3.8.0)
28
- rspec-expectations (3.8.4)
29
- diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.8.0)
31
- rspec-mocks (3.8.1)
32
- diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.8.0)
34
- rspec-support (3.8.2)
35
- rubocop (0.74.0)
36
- jaro_winkler (~> 1.5.1)
37
- parallel (~> 1.10)
38
- parser (>= 2.6)
39
- rainbow (>= 2.2.2, < 4.0)
40
- ruby-progressbar (~> 1.7)
41
- unicode-display_width (>= 1.4.0, < 1.7)
42
- rubocop-rspec (1.35.0)
43
- rubocop (>= 0.60.0)
44
- ruby-progressbar (1.10.1)
45
- unicode-display_width (1.6.0)
46
-
47
- PLATFORMS
48
- ruby
49
-
50
- DEPENDENCIES
51
- bundler (~> 1.17)
52
- fast_ignore!
53
- pry (~> 0)
54
- rake (~> 10.0)
55
- rspec (~> 3.0)
56
- rubocop (>= 0.74.0)
57
- rubocop-rspec (~> 1)
58
-
59
- BUNDLED WITH
60
- 1.17.3
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './rule'
4
-
5
- class FastIgnore
6
- class FileRuleList < ::FastIgnore::RuleList
7
- def initialize(file, root: ::File.dirname(file))
8
- @lines = ::IO.foreach(file)
9
- @root = root
10
- end
11
- end
12
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class FastIgnore
4
- class GitignoreRuleList
5
- include ::Enumerable
6
-
7
- def initialize(file)
8
- @file = file
9
- end
10
-
11
- def each(&block)
12
- ::FastIgnore::RuleList.new('.git').each(&block)
13
- ::FastIgnore::FileRuleList.new(file).each(&block)
14
- end
15
-
16
- private
17
-
18
- attr_reader :file
19
- end
20
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class FastIgnore
4
- class RuleList
5
- include ::Enumerable
6
-
7
- def initialize(*lines, root: ::Dir.pwd, expand_path: false)
8
- @lines = lines
9
- @root = root
10
- @expand_path = expand_path
11
- end
12
-
13
- def each(&block)
14
- return enumerator unless block_given?
15
-
16
- enumerator.each(&block)
17
- end
18
-
19
- private
20
-
21
- attr_reader :lines, :root, :expand_path
22
-
23
- def enumerator
24
- ::Enumerator.new do |yielder|
25
- lines.reverse_each do |rule|
26
- rule = ::FastIgnore::Rule.new(rule, root: root, expand_path: expand_path)
27
- yielder << rule unless rule.skip?
28
- end
29
- end
30
- end
31
- end
32
- end