Module: ActiveRecord::AttributeMethods::Dirty
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Dirty
- Defined in:
- lib/active_record/attribute_methods/dirty.rb
Overview
:nodoc:
Instance Method Summary collapse
- #attribute_changed_in_place?(attr_name) ⇒ Boolean
- #changed_attributes ⇒ Object
- #changes ⇒ Object
- #changes_applied ⇒ Object
- #clear_attribute_changes(attr_names) ⇒ Object
- #clear_changes_information ⇒ Object
-
#initialize_dup(other) ⇒ Object
:nodoc:.
- #previous_changes ⇒ Object
- #raw_write_attribute(attr_name) ⇒ Object
-
#reload ⇒ Object
reload
the record and clears changed attributes. -
#save ⇒ Object
Attempts to
save
the record and clears changed attributes if successful. -
#save! ⇒ Object
Attempts to
save!
the record and clears changed attributes if successful.
Instance Method Details
#attribute_changed_in_place?(attr_name) ⇒ Boolean
97 98 99 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 97 def attribute_changed_in_place?(attr_name) mutation_tracker.changed_in_place?(attr_name) end |
#changed_attributes ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 77 def changed_attributes # This should only be set by methods which will call changed_attributes # multiple times when it is known that the computed value cannot change. if defined?(@cached_changed_attributes) @cached_changed_attributes else super.reverse_merge(mutation_tracker.changed_values).freeze end end |
#changes ⇒ Object
87 88 89 90 91 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 87 def changes cache_changed_attributes do super end end |
#changes_applied ⇒ Object
52 53 54 55 56 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 52 def changes_applied @previous_mutation_tracker = mutation_tracker @changed_attributes = HashWithIndifferentAccess.new store_original_attributes end |
#clear_attribute_changes(attr_names) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 70 def clear_attribute_changes(attr_names) super attr_names.each do |attr_name| clear_attribute_change(attr_name) end end |
#clear_changes_information ⇒ Object
58 59 60 61 62 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 58 def clear_changes_information @previous_mutation_tracker = nil @changed_attributes = HashWithIndifferentAccess.new store_original_attributes end |
#initialize_dup(other) ⇒ Object
:nodoc:
44 45 46 47 48 49 50 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 44 def initialize_dup(other) # :nodoc: super @attributes = self.class._default_attributes.map do |attr| attr.with_value_from_user(@attributes.fetch_value(attr.name)) end @mutation_tracker = nil end |
#previous_changes ⇒ Object
93 94 95 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 93 def previous_changes previous_mutation_tracker.changes end |
#raw_write_attribute(attr_name) ⇒ Object
64 65 66 67 68 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 64 def raw_write_attribute(attr_name, *) result = super clear_attribute_change(attr_name) result end |
#reload ⇒ Object
reload
the record and clears changed attributes.
36 37 38 39 40 41 42 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 36 def reload(*) super.tap do @mutation_tracker = nil @previous_mutation_tracker = nil @changed_attributes = HashWithIndifferentAccess.new end end |
#save ⇒ Object
Attempts to save
the record and clears changed attributes if successful.
21 22 23 24 25 26 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 21 def save(*) if status = super changes_applied end status end |
#save! ⇒ Object
Attempts to save!
the record and clears changed attributes if successful.
29 30 31 32 33 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 29 def save!(*) super.tap do changes_applied end end |