Class: TestChanges::FindingPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/test_changes/finding_pattern.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FindingPattern

Returns a new instance of FindingPattern.



7
8
9
10
# File 'lib/test_changes/finding_pattern.rb', line 7

def initialize(options = {})
  @matching_pattern = options[:matching_pattern]
  @substitution_patterns = options[:substitution_patterns]
end

Instance Attribute Details

#matching_patternObject (readonly)

Returns the value of attribute matching_pattern.



5
6
7
# File 'lib/test_changes/finding_pattern.rb', line 5

def matching_pattern
  @matching_pattern
end

#substitution_patternsObject (readonly)

Returns the value of attribute substitution_patterns.



5
6
7
# File 'lib/test_changes/finding_pattern.rb', line 5

def substitution_patterns
  @substitution_patterns
end

Class Method Details

.build(patterns) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/test_changes/finding_pattern.rb', line 23

def self.build(patterns)
  patterns.map do |pattern, substitution_patterns|
    new(
      matching_pattern: /#{pattern}/,
      substitution_patterns: [substitution_patterns].flatten
    )
  end
end

Instance Method Details

#matching_paths(path) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/test_changes/finding_pattern.rb', line 12

def matching_paths(path)
  results = substitution_patterns.flat_map do |substitution_pattern|
    if matches?(path)
      substituted_pattern = path.sub(matching_pattern, substitution_pattern)
      Pathname.glob(substituted_pattern)
    end
  end

  results.compact.map(&:to_s)
end