Class: ActiveModel::ForcedMutationTracker
Overview
Constant Summary
AttributeMutationTracker::OPTION_NOT_GIVEN
Instance Method Summary
collapse
#any_changes?, #changed?, #changed_attribute_names, #changed_values, #changes
Constructor Details
#initialize(attributes, forced_changes = {}) ⇒ ForcedMutationTracker
Returns a new instance of ForcedMutationTracker.
85
86
87
88
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 85
def initialize(attributes, forced_changes = {})
super
@finalized_changes = nil
end
|
Instance Method Details
#change_to_attribute(attr_name) ⇒ Object
94
95
96
97
98
99
100
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 94
def change_to_attribute(attr_name)
if finalized_changes&.include?(attr_name)
finalized_changes[attr_name].dup
else
super
end
end
|
#changed_in_place?(attr_name) ⇒ Boolean
90
91
92
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 90
def changed_in_place?(attr_name)
false
end
|
#finalize_changes ⇒ Object
118
119
120
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 118
def finalize_changes
@finalized_changes = changes
end
|
#force_change(attr_name) ⇒ Object
114
115
116
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 114
def force_change(attr_name)
forced_changes[attr_name] = clone_value(attr_name) unless attribute_changed?(attr_name)
end
|
#forget_change(attr_name) ⇒ Object
102
103
104
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 102
def forget_change(attr_name)
forced_changes.delete(attr_name)
end
|
#original_value(attr_name) ⇒ Object
106
107
108
109
110
111
112
|
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 106
def original_value(attr_name)
if changed?(attr_name)
forced_changes[attr_name]
else
fetch_value(attr_name)
end
end
|