Module: ActiveRecord::AttributeMethods::Dirty

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Dirty
Defined in:
lib/active_record/attribute_methods/dirty.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#attribute_changed_in_place?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/active_record/attribute_methods/dirty.rb', line 72

def attribute_changed_in_place?(attr_name)
  old_value = original_raw_attribute(attr_name)
  @attributes[attr_name].changed_in_place_from?(old_value)
end

#changed_attributesObject



56
57
58
59
60
61
62
63
64
# File 'lib/active_record/attribute_methods/dirty.rb', line 56

def changed_attributes
  # This should only be set by methods which will call changed_attributes
  # multiple times when it is known that the computed value cannot change.
  if defined?(@cached_changed_attributes)
    @cached_changed_attributes
  else
    super.reverse_merge(attributes_changed_in_place).freeze
  end
end

#changesObject



66
67
68
69
70
# File 'lib/active_record/attribute_methods/dirty.rb', line 66

def changes
  cache_changed_attributes do
    super
  end
end

#changes_appliedObject



46
47
48
49
# File 'lib/active_record/attribute_methods/dirty.rb', line 46

def changes_applied
  super
  store_original_raw_attributes
end

#clear_changes_informationObject



51
52
53
54
# File 'lib/active_record/attribute_methods/dirty.rb', line 51

def clear_changes_information
  super
  original_raw_attributes.clear
end

#initialize_dup(other) ⇒ Object

:nodoc:



41
42
43
44
# File 'lib/active_record/attribute_methods/dirty.rb', line 41

def initialize_dup(other) # :nodoc:
  super
  calculate_changes_from_defaults
end

#reloadObject

reload the record and clears changed attributes.



35
36
37
38
39
# File 'lib/active_record/attribute_methods/dirty.rb', line 35

def reload(*)
  super.tap do
    clear_changes_information
  end
end

#saveObject

Attempts to save the record and clears changed attributes if successful.



20
21
22
23
24
25
# File 'lib/active_record/attribute_methods/dirty.rb', line 20

def save(*)
  if status = super
    changes_applied
  end
  status
end

#save!Object

Attempts to save! the record and clears changed attributes if successful.



28
29
30
31
32
# File 'lib/active_record/attribute_methods/dirty.rb', line 28

def save!(*)
  super.tap do
    changes_applied
  end
end