class TestChanges::FindingPattern

Attributes

matching_pattern[R]
substitution_patterns[R]

Public Class Methods

build(patterns) click to toggle source
# 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
new(options = {}) click to toggle source
# File lib/test_changes/finding_pattern.rb, line 7
def initialize(options = {})
  @matching_pattern = options[:matching_pattern]
  @substitution_patterns = options[:substitution_patterns]
end

Public Instance Methods

matching_paths(path) click to toggle source
# 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

Private Instance Methods

matches?(path) click to toggle source
# File lib/test_changes/finding_pattern.rb, line 34
def matches?(path)
  path =~ matching_pattern
end