Class: Katalyst::Content::DuplicatesAssociations::DupOne
- Inherits:
-
Object
- Object
- Katalyst::Content::DuplicatesAssociations::DupOne
- Defined in:
- app/models/concerns/katalyst/content/duplicates_associations.rb
Overview
Duplicates a has_one 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::DupOne.new(:detail).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) ⇒ DupOne
constructor
A new instance of DupOne.
Constructor Details
#initialize(name) ⇒ DupOne
Returns a new instance of DupOne.
44 45 46 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 44 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
42 43 44 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 42 def name @name end |
Instance Method Details
#apply(source, target) ⇒ Object
48 49 50 51 52 |
# File 'app/models/concerns/katalyst/content/duplicates_associations.rb', line 48 def apply(source, target) record = source.public_send(name) target.public_send("#{name}=", record.dup) unless record.nil? || record.marked_for_destruction? end |