Class: Katalyst::Content::DuplicatesAssociations::DupMany
- Inherits:
-
Object
- Object
- Katalyst::Content::DuplicatesAssociations::DupMany
- Defined in:
- app/models/concerns/katalyst/content/duplicates_associations.rb
Overview
Duplicates a has_many association from source to target. Public API: can be used directly for models that want to duplicate a specific association without including the concern, e.g. DuplicatesAssociations::DupMany.new(:notes).apply(source, self)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #apply(source, target) ⇒ Object
-
#initialize(name) ⇒ DupMany
constructor
A new instance of DupMany.
Constructor Details
#initialize(name) ⇒ DupMany
Returns a new instance of DupMany.
62 63 64 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 62 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
60 61 62 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 60 def name @name end |
Instance Method Details
#apply(source, target) ⇒ Object
66 67 68 69 70 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 66 def apply(source, target) records = source.public_send(name).reject(&:marked_for_destruction?).map(&:dup) target.public_send("#{name}=", records) if records.any? end |