Class: ActiveRecord::AttributeMutationTracker
- Inherits:
-
Object
- Object
- ActiveRecord::AttributeMutationTracker
- Defined in:
- lib/active_record/attribute_mutation_tracker.rb
Overview
:nodoc:
Instance Method Summary collapse
- #changed?(attr_name) ⇒ Boolean
- #changed_in_place?(attr_name) ⇒ Boolean
- #changed_values ⇒ Object
- #changes ⇒ Object
- #forget_change(attr_name) ⇒ Object
-
#initialize(attributes) ⇒ AttributeMutationTracker
constructor
A new instance of AttributeMutationTracker.
Constructor Details
#initialize(attributes) ⇒ AttributeMutationTracker
Returns a new instance of AttributeMutationTracker.
3 4 5 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 3 def initialize(attributes) @attributes = attributes end |
Instance Method Details
#changed?(attr_name) ⇒ Boolean
23 24 25 26 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 23 def changed?(attr_name) attr_name = attr_name.to_s attributes[attr_name].changed? end |
#changed_in_place?(attr_name) ⇒ Boolean
28 29 30 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 28 def changed_in_place?(attr_name) attributes[attr_name].changed_in_place? end |
#changed_values ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 7 def changed_values attr_names.each_with_object({}.with_indifferent_access) do |attr_name, result| if changed?(attr_name) result[attr_name] = attributes[attr_name].original_value end end end |
#changes ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 15 def changes attr_names.each_with_object({}.with_indifferent_access) do |attr_name, result| if changed?(attr_name) result[attr_name] = [attributes[attr_name].original_value, attributes.fetch_value(attr_name)] end end end |
#forget_change(attr_name) ⇒ Object
32 33 34 35 |
# File 'lib/active_record/attribute_mutation_tracker.rb', line 32 def forget_change(attr_name) attr_name = attr_name.to_s attributes[attr_name] = attributes[attr_name].forgetting_assignment end |