module Para::Cloneable::ClassMethods
Public Instance Methods
acts_as_cloneable(*args)
click to toggle source
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.
# File lib/para/cloneable.rb, line 59 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 # If `acts_as_cloneable` is called multiple times, for example by a parent class # and the by its subclass, ensure that we don't lose the previously defined # cloneable options, to avoid having to repeat the same include options in each # subclass, if it has to define subclass specific cloneable options. previous_cloneable_options = cloneable_options || {} # Prepare the new cloneable options hash with the provided arguments new_cloneable_options = options.reverse_merge({ include: args }) # Merges previous and new cloneable options into the cloneable_options class # attribute, also merging the `:include` array self.cloneable_options = previous_cloneable_options.merge(new_cloneable_options) do |key, a, b| a.is_a?(Array) && b.is_a?(Array) ? (a + b).uniq : b end end
cloneable?()
click to toggle source
# File lib/para/cloneable.rb, line 87 def cloneable? @cloneable ||= false end