Module: ActiveRecordCloning::ClassMethods
- Defined in:
- lib/rails_core_extensions/active_record_cloning.rb
Instance Method Summary collapse
- #attributes_excluded_from_cloning ⇒ Object
- #attributes_included_in_cloning ⇒ Object
- #clones_attributes(*attributes) ⇒ Object
- #clones_attributes_except(*attributes) ⇒ Object
- #clones_attributes_reset ⇒ Object
- #exclude_attributes(cloned, excludes) ⇒ Object
- #excluded_attributes(excludes) ⇒ Object
- #inherited(subclass) ⇒ Object
Instance Method Details
#attributes_excluded_from_cloning ⇒ Object
15 16 17 |
# 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 ⇒ Object
11 12 13 |
# 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) ⇒ Object
19 20 21 |
# 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) ⇒ Object
23 24 25 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/rails_core_extensions/active_record_cloning.rb', line 27 def clones_attributes_reset @cloned_attributes = nil end |
#exclude_attributes(cloned, excludes) ⇒ Object
31 32 33 34 35 |
# 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) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# 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) ⇒ Object
6 7 8 9 |
# File 'lib/rails_core_extensions/active_record_cloning.rb', line 6 def inherited(subclass) super subclass.cloned_attributes_hash = cloned_attributes_hash end |