Class: Mantra::Transform::Rename

Inherits:
Mantra::Transform show all
Defined in:
lib/mantra/transform/rename.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 Attribute Details

#manifestObject Also known as: result

Returns the value of attribute manifest.



5
6
7
# File 'lib/mantra/transform/rename.rb', line 5

def manifest
  @manifest
end

Instance Method Details

#performObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mantra/transform/rename.rb', line 18

def perform
  @manifest = previous_transform.result
  elemenents_to_rename = @manifest.select(section)
  elemenents_to_rename.each do |element|
    parent = element.parent
    raise Mantra::Transform::ValidationError.new ("parent should be a hash") unless parent.hash?
    unless parent.find(new_name).nil?
      raise Mantra::Transform::ValidationError.new("Section with the name #{new_name} already exists.")
    end
    old_name = parent.selector_for(element)
    parent.content[new_name] = element
    parent.content.delete(old_name)
  end
end