Class: Caster::Rename

Inherits:
Object
  • Object
show all
Defined in:
lib/caster/transform/rename.rb

Instance Method Summary collapse

Constructor Details

#initialize(old_name, new_name) ⇒ Rename

Returns a new instance of Rename.



6
7
8
9
10
# File 'lib/caster/transform/rename.rb', line 6

def initialize old_name, new_name
  @old_name = old_name
  @new_name = new_name
  @accessor = Accessor.new
end

Instance Method Details

#execute(doc) ⇒ Object



12
13
14
15
16
17
# File 'lib/caster/transform/rename.rb', line 12

def execute doc
  doc[@new_name] = doc[@old_name]
  @accessor.set(doc, @new_name, @accessor.get(doc, @old_name))
  @accessor.delete doc, @old_name
  doc
end