Module: ActiveRecord::AttributeMethods::Dirty

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

Overview

:nodoc:

Constant Summary

Constants included from ActiveModel::AttributeMethods

ActiveModel::AttributeMethods::CALL_COMPILABLE_REGEXP, ActiveModel::AttributeMethods::NAME_COMPILABLE_REGEXP

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, class_methods, extended, included

Methods included from ActiveModel::Dirty

#attribute_changed?, #attribute_was, #changed, #changed?, #previous_changes, #restore_attributes

Methods included from ActiveModel::AttributeMethods

#attribute_missing, #method_missing, #respond_to?, #respond_to_without_attributes?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveModel::AttributeMethods

Instance Method Details

#attribute_changed_in_place?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)

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

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


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

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


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

def changes
  cache_changed_attributes do
    super
  end
end

#changes_appliedObject


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

def changes_applied
  super
  store_original_raw_attributes
end

#clear_changes_informationObject


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

def clear_changes_information
  super
  original_raw_attributes.clear
end

#initialize_dup(other) ⇒ Object

:nodoc:


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

def initialize_dup(other) # :nodoc:
  super
  @original_raw_attributes = nil
  calculate_changes_from_defaults
end

#reloadObject

reload the record and clears changed attributes.


35
36
37
38
39
# File 'activerecord/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 'activerecord/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 'activerecord/lib/active_record/attribute_methods/dirty.rb', line 28

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