Class: Steep::Project::Pattern
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#ignore_prefixes ⇒ Object
readonly
Returns the value of attribute ignore_prefixes.
-
#ignores ⇒ Object
readonly
Returns the value of attribute ignores.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
Instance Method Summary collapse
- #=~(path) ⇒ Object
- #empty? ⇒ Boolean
- #ignore?(path) ⇒ Boolean
-
#initialize(patterns:, ignores: [], ext:) ⇒ Pattern
constructor
A new instance of Pattern.
- #match?(path) ⇒ Boolean
- #test_string(path, patterns, prefixes) ⇒ Object
Constructor Details
#initialize(patterns:, ignores: [], ext:) ⇒ Pattern
Returns a new instance of Pattern.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/steep/project/pattern.rb', line 10 def initialize(patterns:, ignores: [], ext:) @patterns = patterns @ignores = ignores @ext = ext @prefixes = patterns.map do |pat| if pat == "." || pat == "./" "" else pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator end end @ignore_prefixes = ignores.map do |pat| if pat == "." || pat == "./" "" else pat.delete_prefix("./").delete_suffix(File::Separator) << File::Separator end end end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
8 9 10 |
# File 'lib/steep/project/pattern.rb', line 8 def ext @ext end |
#ignore_prefixes ⇒ Object (readonly)
Returns the value of attribute ignore_prefixes.
7 8 9 |
# File 'lib/steep/project/pattern.rb', line 7 def ignore_prefixes @ignore_prefixes end |
#ignores ⇒ Object (readonly)
Returns the value of attribute ignores.
5 6 7 |
# File 'lib/steep/project/pattern.rb', line 5 def ignores @ignores end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
4 5 6 |
# File 'lib/steep/project/pattern.rb', line 4 def patterns @patterns end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
6 7 8 |
# File 'lib/steep/project/pattern.rb', line 6 def prefixes @prefixes end |
Instance Method Details
#=~(path) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/steep/project/pattern.rb', line 31 def =~(path) unless path.is_a?(Pathname) path = Pathname(path.to_s) end match?(path) && !ignore?(path) end |
#empty? ⇒ Boolean
54 55 56 |
# File 'lib/steep/project/pattern.rb', line 54 def empty? patterns.empty? end |
#ignore?(path) ⇒ Boolean
43 44 45 |
# File 'lib/steep/project/pattern.rb', line 43 def ignore?(path) test_string(path, ignores, ignore_prefixes) end |
#match?(path) ⇒ Boolean
39 40 41 |
# File 'lib/steep/project/pattern.rb', line 39 def match?(path) test_string(path, patterns, prefixes) end |
#test_string(path, patterns, prefixes) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/steep/project/pattern.rb', line 47 def test_string(path, patterns, prefixes) string = path.to_s patterns.any? {|pat| File.fnmatch(pat, string, File::FNM_PATHNAME) } || prefixes.any? {|prefix| File.fnmatch("#{prefix}**/*#{ext}", string, File::FNM_PATHNAME) } end |