Class: Cimas::Patch
- Inherits:
-
Object
- Object
- Cimas::Patch
- Defined in:
- lib/cimas/patch.rb
Overview
Value object over one patches: entry in cimas.yml — an in-place
regex find/replace applied to files already present in each target
repo (unlike files: sync, which replaces whole files). See the
Patches section of README.adoc.
Instance Attribute Summary collapse
-
#find_regexp ⇒ Object
readonly
Returns the value of attribute find_regexp.
-
#globs ⇒ Object
readonly
Returns the value of attribute globs.
-
#group_names ⇒ Object
readonly
Returns the value of attribute group_names.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
- #apply(content) ⇒ Object
-
#initialize(name, attributes) ⇒ Patch
constructor
A new instance of Patch.
- #matches?(content) ⇒ Boolean
Constructor Details
#initialize(name, attributes) ⇒ Patch
Returns a new instance of Patch.
9 10 11 12 13 14 15 |
# File 'lib/cimas/patch.rb', line 9 def initialize(name, attributes) @name = name @globs = Array(attributes["files"]) @find_regexp = Regexp.new(attributes["find"]) @replacement = attributes["replace"] @group_names = attributes["groups"] || [] end |
Instance Attribute Details
#find_regexp ⇒ Object (readonly)
Returns the value of attribute find_regexp.
7 8 9 |
# File 'lib/cimas/patch.rb', line 7 def find_regexp @find_regexp end |
#globs ⇒ Object (readonly)
Returns the value of attribute globs.
7 8 9 |
# File 'lib/cimas/patch.rb', line 7 def globs @globs end |
#group_names ⇒ Object (readonly)
Returns the value of attribute group_names.
7 8 9 |
# File 'lib/cimas/patch.rb', line 7 def group_names @group_names end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/cimas/patch.rb', line 7 def name @name end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
7 8 9 |
# File 'lib/cimas/patch.rb', line 7 def replacement @replacement end |
Instance Method Details
#apply(content) ⇒ Object
21 22 23 |
# File 'lib/cimas/patch.rb', line 21 def apply(content) content.gsub(find_regexp, replacement) end |
#matches?(content) ⇒ Boolean
17 18 19 |
# File 'lib/cimas/patch.rb', line 17 def matches?(content) find_regexp.match?(content) end |