Class: TestChanges::FindingPattern
- Inherits:
-
Object
- Object
- TestChanges::FindingPattern
- Defined in:
- lib/test_changes/finding_pattern.rb
Instance Attribute Summary collapse
-
#matching_pattern ⇒ Object
readonly
Returns the value of attribute matching_pattern.
-
#substitution_patterns ⇒ Object
readonly
Returns the value of attribute substitution_patterns.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FindingPattern
constructor
A new instance of FindingPattern.
- #matching_paths(path) ⇒ Object
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( = {}) @matching_pattern = [:matching_pattern] @substitution_patterns = [:substitution_patterns] end |
Instance Attribute Details
#matching_pattern ⇒ Object (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_patterns ⇒ Object (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 |