Module: Para::Cloneable::ClassMethods

Defined in:
lib/para/cloneable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_cloneable(*args) ⇒ Object

Allow configuring cloneable options for the model, and making the model cloneable in the admin

The provided arguments are the cloneable associations for the model, and keyword arguments are passed to the #deep_clone method.

An optional :prepare keyword argument can be passed and will be called by #deep_clone to allow altering the cloned resource before saving it.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/para/cloneable.rb', line 57

def acts_as_cloneable(*args)
  @cloneable = true

  options = args.extract_options!

  # Allow nested STI resources to define their own relations to clone even
  # if other sibling models don't define those relations
  options[:skip_missing_associations] = true

  self.cloneable_options = options.reverse_merge({
    include: args
  })
end

#cloneable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/para/cloneable.rb', line 71

def cloneable?
  @cloneable ||= false
end