Class: PathList::Matchers::WithinDir

Inherits:
Object
  • Object
show all
Defined in:
lib/path_list/matchers/within_dir.rb

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (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

#weightObject



31
32
33
# File 'lib/path_list/matchers/within_dir.rb', line 31

def weight
  @dir_matchers.length + (@has_shebang_matchers ? 10 : 0)
end