Class: PathList::Matchers::WithinDir
- Inherits:
-
Object
- Object
- PathList::Matchers::WithinDir
- Defined in:
- lib/path_list/matchers/within_dir.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(matchers, root) ⇒ WithinDir
constructor
A new instance of WithinDir.
- #match?(root_candidate) ⇒ Boolean
- #weight ⇒ Object
Constructor Details
#initialize(matchers, root) ⇒ WithinDir
Returns a new instance of WithinDir.
6 7 8 9 10 11 12 13 |
# File 'lib/path_list/matchers/within_dir.rb', line 6 def initialize(matchers, root) @dir_matchers = squash_matchers(matchers.reject(&:file_only?)) @file_matchers = squash_matchers(matchers.reject(&:dir_only?)) @has_shebang_matchers = matchers.any?(&:shebang?) @root = root freeze end |
Instance Method Details
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/path_list/matchers/within_dir.rb', line 27 def empty? @dir_matchers.empty? && @file_matchers.empty? end |
#match?(root_candidate) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/path_list/matchers/within_dir.rb', line 15 def match?(root_candidate) relative_candidate = root_candidate.relative_to(@root) return false unless relative_candidate (root_candidate.directory? ? @dir_matchers : @file_matchers).reverse_each do |rule| val = rule.match?(relative_candidate) return val if val end false end |
#weight ⇒ Object
31 32 33 |
# File 'lib/path_list/matchers/within_dir.rb', line 31 def weight @dir_matchers.length + (@has_shebang_matchers ? 10 : 0) end |