Class: ActiveModel::ForcedMutationTracker

Inherits:
AttributeMutationTracker show all
Defined in:
lib/active_model/attribute_mutation_tracker.rb

Overview

:nodoc:

Constant Summary

Constants inherited from AttributeMutationTracker

AttributeMutationTracker::OPTION_NOT_GIVEN

Instance Method Summary collapse

Methods inherited from AttributeMutationTracker

#any_changes?, #changed?, #changed_attribute_names, #changed_values, #changes

Constructor Details

#initialize(attributes) ⇒ ForcedMutationTracker

Returns a new instance of ForcedMutationTracker.



92
93
94
95
# File 'lib/active_model/attribute_mutation_tracker.rb', line 92

def initialize(attributes)
  super
  @finalized_changes = nil
end

Instance Method Details

#change_to_attribute(attr_name) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/active_model/attribute_mutation_tracker.rb', line 101

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

Returns:

  • (Boolean)


97
98
99
# File 'lib/active_model/attribute_mutation_tracker.rb', line 97

def changed_in_place?(attr_name)
  false
end

#finalize_changesObject



125
126
127
# File 'lib/active_model/attribute_mutation_tracker.rb', line 125

def finalize_changes
  @finalized_changes = changes
end

#force_change(attr_name) ⇒ Object



121
122
123
# File 'lib/active_model/attribute_mutation_tracker.rb', line 121

def force_change(attr_name)
  forced_changes[attr_name] = clone_value(attr_name) unless attribute_changed?(attr_name)
end

#forget_change(attr_name) ⇒ Object



109
110
111
# File 'lib/active_model/attribute_mutation_tracker.rb', line 109

def forget_change(attr_name)
  forced_changes.delete(attr_name)
end

#original_value(attr_name) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/active_model/attribute_mutation_tracker.rb', line 113

def original_value(attr_name)
  if changed?(attr_name)
    forced_changes[attr_name]
  else
    fetch_value(attr_name)
  end
end