Class: Mantra::Transform::TemplatizeValue

Inherits:
Mantra::Transform show all
Includes:
Helpers::RegexpHelper
Defined in:
lib/mantra/transform/templatize_value.rb

Instance Method Summary collapse

Methods included from Helpers::RegexpHelper

#to_regexp

Methods inherited from Mantra::Transform

description, #ensure_yml_file_exist, input, inputs, #merge_tool, #previous_transform, #raise_error_if_no_source_manifest, #run, #source_manifest, #target_manifest, #validate_inputs

Methods included from Helpers::ObjectWithType

included

Instance Method Details

#performObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mantra/transform/templatize_value.rb', line 31

def perform
  raise_error_if_no_source_manifest
  ensure_yml_file_exist(self.target)
  # value_matcher = to_regexp(value)

  raise "scope must not match value wildcard" if scope.match(value)

  source_manifest.traverse do |node|
    if node.content.to_s.match(value)
      # match = node.content.to_s.match(value_matcher)[0]
      match = node.content.to_s.match(value)[0]
      begin_index = node.content.to_s.index(match)
      end_index   = begin_index + match.size
      final_value = merge_tool.templatize(node.content.to_s, scope, begin_index, end_index)
      node.content = final_value
      scope_element = Manifest::Element.element_with_selector(scope, value)
      target_manifest.merge(scope_element)
    end
  end

  source_manifest.save
  target_manifest.save
end

#raise_if_no_source_manifestObject



55
56
57
58
59
# File 'lib/mantra/transform/templatize_value.rb', line 55

def raise_if_no_source_manifest
  if self.source.nil? || !File.exist?(self.source)
    raise Manifest::FileNotFoundError.new("Source manifest does not exist: #{self.source.inspect}")
  end
end