module ActiveRecordCloning::ClassMethods

Public Instance Methods

attributes_excluded_from_cloning() click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 15
def attributes_excluded_from_cloning
  cloned_attributes_hash[:exclude].dup
end
attributes_included_in_cloning() click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 11
def attributes_included_in_cloning
  cloned_attributes_hash[:include].dup
end
clones_attributes(*attributes) click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 19
def clones_attributes(*attributes)
  cloned_attributes_hash[:include] = attributes.map(&:to_sym)
end
clones_attributes_except(*attributes) click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 23
def clones_attributes_except(*attributes)
  cloned_attributes_hash[:exclude] = attributes.map(&:to_sym)
end
clones_attributes_reset() click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 27
def clones_attributes_reset
  @cloned_attributes = nil
end
exclude_attributes(cloned, excludes) click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 31
def exclude_attributes(cloned, excludes)
  excluded_attributes(excludes).each do |attr|
    cloned.send("#{attr}=", nil)
  end
end
excluded_attributes(excludes) click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 37
def excluded_attributes(excludes)
  all_attributes = attribute_names.map(&:to_sym)
  included_attributes = if attributes_included_in_cloning.empty?
    all_attributes
  else
    all_attributes & attributes_included_in_cloning
  end
  all_attributes - included_attributes + attributes_excluded_from_cloning + excludes
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/rails_core_extensions/active_record_cloning.rb, line 6
def inherited(subclass)
  super
  subclass.cloned_attributes_hash = cloned_attributes_hash
end

Protected Instance Methods

cloned_attributes_hash() click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 49
def cloned_attributes_hash
  @cloned_attributes ||= {:include => [], :exclude => []}
end
cloned_attributes_hash=(attributes_hash) click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 53
def cloned_attributes_hash=(attributes_hash)
  @cloned_attributes = attributes_hash
end