Module: Para::Cloneable

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Defined in:
lib/para/cloneable.rb,
lib/para/cloneable/attachments_cloner.rb,
lib/para/cloneable/include_tree_builder.rb

Defined Under Namespace

Modules: ClassMethods Classes: AttachmentsCloner, IncludeTreeBuilder

Instance Method Summary collapse

Instance Method Details

#deep_clone!(options = {}) ⇒ Object

Wraps the deep_cloneable gem #deep_clone method to allow using the predefined associations and options from our Cloneable.acts_as_cloneable macro.



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/para/cloneable.rb', line 19

def deep_clone!(options = {})
  dictionary = options[:dictionary] ||= {}

  processed_options = Para::Cloneable::IncludeTreeBuilder.new(self).build
  options = options.reverse_merge(processed_options)
  callback = build_clone_callback(options.delete(:prepare))

  deep_clone(options) do |original, clone|
    Para::Cloneable::AttachmentsCloner.new(original, clone, dictionary).clone!
    callback&.call(original, clone)
  end
end