Class: Cimas::Patch

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_regexpObject (readonly)

Returns the value of attribute find_regexp.



7
8
9
# File 'lib/cimas/patch.rb', line 7

def find_regexp
  @find_regexp
end

#globsObject (readonly)

Returns the value of attribute globs.



7
8
9
# File 'lib/cimas/patch.rb', line 7

def globs
  @globs
end

#group_namesObject (readonly)

Returns the value of attribute group_names.



7
8
9
# File 'lib/cimas/patch.rb', line 7

def group_names
  @group_names
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cimas/patch.rb', line 7

def name
  @name
end

#replacementObject (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

Returns:

  • (Boolean)


17
18
19
# File 'lib/cimas/patch.rb', line 17

def matches?(content)
  find_regexp.match?(content)
end