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.



88
89
90
91
# File 'lib/active_model/attribute_mutation_tracker.rb', line 88

def initialize(attributes)
  super
  @finalized_changes = nil
end

Instance Method Details

#change_to_attribute(attr_name) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/active_model/attribute_mutation_tracker.rb', line 97

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)


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

def changed_in_place?(attr_name)
  false
end

#finalize_changesObject



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

def finalize_changes
  @finalized_changes = changes
end

#force_change(attr_name) ⇒ Object



117
118
119
# File 'lib/active_model/attribute_mutation_tracker.rb', line 117

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

#forget_change(attr_name) ⇒ Object



105
106
107
# File 'lib/active_model/attribute_mutation_tracker.rb', line 105

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

#original_value(attr_name) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/active_model/attribute_mutation_tracker.rb', line 109

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