rocksolidwebdesign/amoeba — pull request #22 by AdRulz (2013-03-19 09:24:09+00:00)
Title: Make it possible to set custom duplication method and also remap associations for created model

Use case
``` ruby
class ObjectPrototype < ActiveRecord::Base
has_many :child_prototypes

amoeba do
method :become_real
remapper :remap_associations
end

def become_real
self.dup().becomes( RealObject )
end

def remap_associations( name )
'childs' if name == 'child_prototypes'
end
end

class RealObject < ObjectPrototype
has_many :childs
end

class ChildPrototype < ActiveRecord::Base
amoeba do
method :become_child
end

def become_child
self.dup().becomes( Child )
end
end

class Child < ChildPrototype
end
```
Then:
``` ruby
prototype = ObjectPrototype.new
prototype.child_prototypes << ChildPrototype.new
object = prototype.amoeba_dup
object.class # => Object
object.childs.first.class #=> Child
```
It's on top of https://github.com/rocksolidwebdesign/amoeba/pull/21, so:
``` ruby
# class ObjectPrototype
...
def become_real
if amoeba_dup_options[:build]
self.dup().becomes( RealObject )
else
self.dup()
end
end
...

prototype = ObjectPrototype.new
prototype.amoeba_dup.class #=> ObjectPrototype
prototype.amoeba_dup({build:true}).class #=> RealObject
```