fast_ignore 0.10.1 → 0.10.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3d94c089fb5c75d6c9d0650d2391d03425c487c81296495f44f35ed1f6d80ac
4
- data.tar.gz: a9bba05df8121aa49d38b39c7aaaa0e3c7d2b30e4b874d083fe517fa36846b97
3
+ metadata.gz: 2dd945c76bf226766ac86086faf839eac44c4c0cce452e2a3a44e7c47964b7f5
4
+ data.tar.gz: a72de31878713db71c94aa8067c87b807f19833eb008a1a6d6e673fcdeff5a7a
5
5
  SHA512:
6
- metadata.gz: e8954fbef86b13d7948744b2c803319b261d67b6afe83412f1e099a377b17adae2aa1106a3445e6f5604449130c8dfc815331fe104f205ca09b87f5ff8caa69e
7
- data.tar.gz: e53891e9d8b056a62ede7399695deb2911d5836ad5b8442b2ef90d7876fb4d794f1665697df6e7eeecf616f828217fce841f96c9bdfd39e73ae6c89594a65d5c
6
+ metadata.gz: cff75a6418ecc958f2a839b9617554e3857763611248063aef27ec244dd0d1b433d61b81bfdb85a74dd8497fea8599f146ae723fd76023aef72285f53a620ecd
7
+ data.tar.gz: 39aeceb2cd078c8b873019b9763eccb01450e408a24c3fb04005f9451879e1a125bcd73f26a1c4e67e6c999e7d6d0f78b4a1b41abbc0a2650ec36bb1ac7adde6
@@ -22,6 +22,7 @@ includefile
22
22
  janky
23
23
  klass
24
24
  llo
25
+ memoize
25
26
  nocov
26
27
  noninfringement
27
28
  params
@@ -47,4 +48,5 @@ txt
47
48
  unrecursive
48
49
  upcase
49
50
  usr
51
+ webpack
50
52
  zsh
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.10.2
2
+ - add FastIgnore#=== as an alias for FastIgnore#allowed? so that FastIgnore objects can be used for case statements.
3
+ - Fix shebangs in non-pwd-root situations
4
+
1
5
  # v0.10.1
2
6
  - Add option to follow symlinks (turns out i needed it)
3
7
  - performance improvements
data/README.md CHANGED
@@ -49,8 +49,27 @@ Like other enumerables, `FastIgnore#each` can return an enumerator
49
49
  FastIgnore.new.each.with_index { |file, index| puts "#{file}#{index}" }
50
50
  ```
51
51
 
52
+ ### `#allowed?`
53
+
54
+ To check if a single file is allowed, use
55
+ ```ruby
56
+ FastIgnore.new.allowed?('relative/path')
57
+ FastIgnore.new.allowed?('./relative/path')
58
+ FastIgnore.new.allowed?('/absolute/path')
59
+ FastIgnore.new.allowed?('~/home/path')
60
+ ```
61
+
62
+ This is aliased as `===` so you can use the FastIgnore object in case statements.
63
+ ```ruby
64
+ case my_path
65
+ when FastIgnore.new then puts my_path
66
+ end
67
+ ```
68
+
69
+ It's recommended to memoize the FastIgnore.new object somehow to avoid having to parse the gitignore file repeatedly.
70
+
52
71
  ### `relative: true`
53
- By default, FastIgnore will return full paths. To return paths relative to the current working directory, or the supplied [`root:`](#root), use:
72
+ By default, FastIgnore.each will yield full paths. To yield paths relative to the current working directory, or if supplied, [`root:`](#root), use:
54
73
 
55
74
  ```ruby
56
75
  FastIgnore.new(relative: true).to_a
@@ -116,16 +135,6 @@ FastIgnore.new(ignore_rules: ['.git', '.gitkeep']).to_a
116
135
  FastIgnore.new(ignore_rules: ".git\n.gitkeep").to_a
117
136
  ```
118
137
 
119
- # `#allowed?`
120
-
121
- To check if a single file is allowed, use
122
- ```ruby
123
- FastIgnore.new.allowed?('relative/path')
124
- FastIgnore.new.allowed?('./relative/path')
125
- FastIgnore.new.allowed?('/absolute/path')
126
- FastIgnore.new.allowed?('~/home/path')
127
- ```
128
-
129
138
  ### `include_files:` and `include_rules:`
130
139
 
131
140
  Building on the gitignore format, FastIgnore also accepts a list of allowed or included files.
data/bin/time CHANGED
@@ -1,6 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # use mac terminal not vs code terminal
5
+ # ensure nothing else is watching that dir in the filesystem e.g. webpack
6
+
4
7
  require 'open3'
5
8
  RUNS = 30
6
9
  SCRIPT = "time #{__dir__}/ls"
data/fast_ignore.gemspec CHANGED
@@ -37,5 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency 'rubocop', '>= 0.74.0'
38
38
  spec.add_development_dependency 'rubocop-rspec', '~> 1'
39
39
  spec.add_development_dependency 'simplecov', '~> 0.18.5'
40
- spec.add_development_dependency 'spellr', '>= 0.8.1'
40
+ spec.add_development_dependency 'spellr', '>= 0.8.3'
41
41
  end
data/lib/fast_ignore.rb CHANGED
@@ -6,6 +6,7 @@ require_relative './fast_ignore/rule_set_builder'
6
6
  require_relative './fast_ignore/rule_builder'
7
7
  require_relative './fast_ignore/rule_set'
8
8
  require_relative './fast_ignore/rule'
9
+ require_relative './fast_ignore/shebang_rule'
9
10
 
10
11
  class FastIgnore
11
12
  class Error < StandardError; end
@@ -25,8 +26,7 @@ class FastIgnore
25
26
  def initialize(relative: false, root: nil, follow_symlinks: false, **rule_set_builder_args)
26
27
  @relative = relative
27
28
  @follow_symlinks = follow_symlinks
28
- dir_pwd = Dir.pwd
29
- @root = "#{::File.expand_path(root.to_s, dir_pwd)}/"
29
+ @root = "#{::File.expand_path(root.to_s, Dir.pwd)}/"
30
30
  @rule_sets = ::FastIgnore::RuleSetBuilder.build(root: @root, **rule_set_builder_args)
31
31
 
32
32
  freeze
@@ -57,10 +57,11 @@ class FastIgnore
57
57
  relative_path = full_path.delete_prefix(@root)
58
58
  filename = ::File.basename(relative_path)
59
59
 
60
- @rule_sets.all? { |r| r.allowed_recursive?(relative_path, false, filename) }
60
+ @rule_sets.all? { |r| r.allowed_recursive?(relative_path, false, full_path, filename) }
61
61
  rescue ::Errno::ENOENT, ::Errno::EACCES, ::Errno::ENOTDIR, ::Errno::ELOOP, ::Errno::ENAMETOOLONG
62
62
  false
63
63
  end
64
+ alias_method :===, :allowed?
64
65
 
65
66
  private
66
67
 
@@ -71,7 +72,7 @@ class FastIgnore
71
72
  relative_path = parent_relative_path + filename
72
73
  dir = directory?(full_path)
73
74
 
74
- next unless @rule_sets.all? { |r| r.allowed_unrecursive?(relative_path, dir, filename) }
75
+ next unless @rule_sets.all? { |r| r.allowed_unrecursive?(relative_path, dir, full_path, filename) }
75
76
 
76
77
  if dir
77
78
  each_recursive(full_path + '/', relative_path + '/', &block)
@@ -10,17 +10,17 @@ class FastIgnore
10
10
 
11
11
  attr_reader :negation
12
12
  alias_method :negation?, :negation
13
+ undef :negation
13
14
 
14
15
  attr_reader :dir_only
15
16
  alias_method :dir_only?, :dir_only
16
-
17
- attr_reader :shebang
18
- alias_method :file_only?, :shebang
17
+ undef :dir_only
19
18
 
20
19
  attr_reader :unanchored
21
20
  alias_method :unanchored?, :unanchored
21
+ undef :unanchored
22
22
 
23
- def initialize(rule, unanchored, dir_only, negation, shebang = nil)
23
+ def initialize(rule, unanchored, dir_only, negation)
24
24
  @rule = rule
25
25
  @unanchored = unanchored
26
26
  @dir_only = dir_only
@@ -30,42 +30,22 @@ class FastIgnore
30
30
  freeze
31
31
  end
32
32
 
33
- # :nocov:
34
- def inspect
35
- if shebang
36
- "#<Rule #{'allow ' if @negation}#!:#{@shebang.to_s[15..-4]}>"
37
- else
38
- "#<Rule #{'!' if @negation}#{@rule}#{'/' if @dir_only}>"
39
- end
33
+ def file_only?
34
+ false
40
35
  end
41
- # :nocov:
42
36
 
43
- def match?(path, filename)
44
- if @shebang
45
- match_shebang?(path, filename)
46
- else
47
- # 14 = FNMATCH_OPTIONS
48
- ::File.fnmatch?(@rule, path, 14)
49
- end
37
+ def shebang
38
+ nil
50
39
  end
51
40
 
52
- def match_shebang?(path, filename)
53
- return false if filename.include?('.')
54
-
55
- first_line(path)&.match?(@shebang)
41
+ # :nocov:
42
+ def inspect
43
+ "#<Rule #{'!' if @negation}#{@rule}#{'/' if @dir_only}>"
56
44
  end
45
+ # :nocov:
57
46
 
58
- def first_line(path)
59
- file = ::File.new(path)
60
- first_line = file.sysread(25)
61
- first_line += file.sysread(50) until first_line.include?("\n")
62
- file.close
63
- first_line
64
- rescue ::EOFError, ::SystemCallError
65
- # :nocov:
66
- file&.close
67
- # :nocov:
68
- first_line
47
+ def match?(relative_path, _, _)
48
+ ::File.fnmatch?(@rule, relative_path, 14)
69
49
  end
70
50
  end
71
51
  end
@@ -2,7 +2,6 @@
2
2
 
3
3
  class FastIgnore
4
4
  module RuleBuilder
5
- # rule or nil
6
5
  class << self
7
6
  # :nocov:
8
7
  if ::FastIgnore::Backports.ruby_version_less_than?(2, 5)
@@ -12,9 +11,9 @@ class FastIgnore
12
11
  # :nocov:
13
12
 
14
13
  def build(rule, allow, expand_path, file_root)
15
- strip(rule)
16
-
17
14
  return shebang_rules(rule, allow) if remove_shebang(rule)
15
+
16
+ strip(rule)
18
17
  return [] if skip?(rule)
19
18
 
20
19
  gitignore_rules(rule, allow, expand_path, file_root)
@@ -36,7 +35,7 @@ class FastIgnore
36
35
  end
37
36
 
38
37
  def shebang_rules(rule, allow)
39
- rules = [::FastIgnore::Rule.new(nil, true, false, allow, /\A#!.*\b#{Regexp.escape(rule)}\b/.freeze)]
38
+ rules = [::FastIgnore::ShebangRule.new(/\A#!.*\b#{Regexp.escape(rule)}\b/.freeze, allow)]
40
39
  return rules unless allow
41
40
 
42
41
  rules << ::FastIgnore::Rule.new('**/*', true, true, true)
@@ -20,16 +20,17 @@ class FastIgnore
20
20
  super
21
21
  end
22
22
 
23
- def allowed_recursive?(path, dir, filename)
24
- @allowed_recursive.fetch(path) do
25
- @allowed_recursive[path] =
26
- allowed_recursive?(::File.dirname(path), true, nil) && allowed_unrecursive?(path, dir, filename)
23
+ def allowed_recursive?(relative_path, dir, full_path, filename)
24
+ @allowed_recursive.fetch(relative_path) do
25
+ @allowed_recursive[relative_path] =
26
+ allowed_recursive?(::File.dirname(relative_path), true, nil, nil) &&
27
+ allowed_unrecursive?(relative_path, dir, full_path, filename)
27
28
  end
28
29
  end
29
30
 
30
- def allowed_unrecursive?(path, dir, filename)
31
+ def allowed_unrecursive?(relative_path, dir, full_path, filename)
31
32
  (dir ? @dir_rules : @file_rules).reverse_each do |rule|
32
- return rule.negation? if rule.match?(path, filename)
33
+ return rule.negation? if rule.match?(relative_path, full_path, filename)
33
34
  end
34
35
 
35
36
  (not @allow) || (dir && @any_not_anchored)
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FastIgnore
4
+ class ShebangRule
5
+ attr_reader :negation
6
+ alias_method :negation?, :negation
7
+ undef :negation
8
+
9
+ attr_reader :shebang
10
+
11
+ def initialize(shebang, negation)
12
+ @shebang = shebang
13
+ @negation = negation
14
+
15
+ freeze
16
+ end
17
+
18
+ def file_only?
19
+ true
20
+ end
21
+
22
+ def dir_only?
23
+ false
24
+ end
25
+
26
+ def unanchored?
27
+ true
28
+ end
29
+
30
+ # :nocov:
31
+ def inspect
32
+ "#<ShebangRule #{'allow ' if @negation}#!:#{@shebang.to_s[15..-4]}>"
33
+ end
34
+ # :nocov:
35
+
36
+ def match?(_, full_path, filename)
37
+ return false if filename.include?('.')
38
+
39
+ first_line(full_path)&.match?(@shebang)
40
+ end
41
+
42
+ private
43
+
44
+ def first_line(path)
45
+ file = ::File.new(path)
46
+ first_line = file.sysread(25)
47
+ first_line += file.sysread(50) until first_line.include?("\n")
48
+ file.close
49
+ first_line
50
+ rescue ::EOFError, ::SystemCallError
51
+ # :nocov:
52
+ file&.close
53
+ # :nocov:
54
+ first_line
55
+ end
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FastIgnore
4
- VERSION = '0.10.1'
4
+ VERSION = '0.10.2'
5
5
  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.10.1
4
+ version: 0.10.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-04-22 00:00:00.000000000 Z
11
+ date: 2020-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: 0.8.1
131
+ version: 0.8.3
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
- version: 0.8.1
138
+ version: 0.8.3
139
139
  description:
140
140
  email:
141
141
  - robot@dana.sh
@@ -171,6 +171,7 @@ files:
171
171
  - lib/fast_ignore/rule_builder.rb
172
172
  - lib/fast_ignore/rule_set.rb
173
173
  - lib/fast_ignore/rule_set_builder.rb
174
+ - lib/fast_ignore/shebang_rule.rb
174
175
  - lib/fast_ignore/version.rb
175
176
  homepage: https://github.com/robotdana/fast_ignore
176
177
  licenses: