123456789_123456789_123456789_123456789_123456789_

Class: ActiveModel::ForcedMutationTracker

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveModel::AttributeMutationTracker
Defined in: activemodel/lib/active_model/attribute_mutation_tracker.rb

Constant Summary

AttributeMutationTracker - Inherited

OPTION_NOT_GIVEN

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(attributes) ⇒ ForcedMutationTracker

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 92

def initialize(attributes)
  super
  @finalized_changes = nil
end

Instance Attribute Details

#finalized_changes (readonly, private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 130

attr_reader :finalized_changes

Instance Method Details

#attr_names (private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 132

def attr_names
  forced_changes.keys
end

#attribute_changed?(attr_name) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 136

def attribute_changed?(attr_name)
  forced_changes.include?(attr_name)
end

#change_to_attribute(attr_name)

[ GitHub ]

  
# File 'activemodel/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

[ GitHub ]

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

def changed_in_place?(attr_name)
  false
end

#clone_value(attr_name) (private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 144

def clone_value(attr_name)
  value = fetch_value(attr_name)
  value.duplicable? ? value.clone : value
rescue TypeError, NoMethodError
  value
end

#fetch_value(attr_name) (private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 140

def fetch_value(attr_name)
  attributes.send(:_read_attribute, attr_name)
end

#finalize_changes

[ GitHub ]

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

def finalize_changes
  @finalized_changes = changes
end

#force_change(attr_name)

[ GitHub ]

  
# File 'activemodel/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)

[ GitHub ]

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

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

#original_value(attr_name)

[ GitHub ]

  
# File 'activemodel/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

#type_cast(attr_name, value) (private)

[ GitHub ]

  
# File 'activemodel/lib/active_model/attribute_mutation_tracker.rb', line 151

def type_cast(attr_name, value)
  value
end