module ActiveRecordCloning::ClassMethods
Public Instance Methods
attributes_excluded_from_cloning()
click to toggle source
# File lib/rails_core_extensions/active_record_cloning.rb, line 17 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 13 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 21 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 25 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 29 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 33 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 39 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 8 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 51 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 55 def cloned_attributes_hash=(attributes_hash) @cloned_attributes = attributes_hash end