Class: Katalyst::Content::DuplicatesAssociations::DupOne

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (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