Class: Amoeba::Macros::HasAndBelongsToMany
- Defined in:
- lib/amoeba/macros/has_and_belongs_to_many.rb
Instance Method Summary collapse
- #fill_relation(relation_name, old_obj, clone) ⇒ Object
- #follow(relation_name, _association) ⇒ Object
Methods inherited from Base
inherited, #initialize, #remapped_relation_name
Constructor Details
This class inherits a constructor from Amoeba::Macros::Base
Instance Method Details
#fill_relation(relation_name, old_obj, clone) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/amoeba/macros/has_and_belongs_to_many.rb', line 13 def fill_relation(relation_name, old_obj, clone) # associate this new child to the new parent object old_obj = old_obj.amoeba_dup if clone relation_name = remapped_relation_name(relation_name) @new_object.__send__(relation_name) << old_obj end |
#follow(relation_name, _association) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/amoeba/macros/has_and_belongs_to_many.rb', line 6 def follow(relation_name, _association) clone = @cloner.amoeba.clones.include?(relation_name.to_sym) @old_object.__send__(relation_name).each do |old_obj| fill_relation(relation_name, old_obj, clone) end end |