Module: DuckRecord::AttributeMethods::Dirty

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#attribute_changed_in_place?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/duck_record/attribute_methods/dirty.rb', line 65

def attribute_changed_in_place?(attr_name)
  mutation_tracker.changed_in_place?(attr_name)
end

#changed_attributesObject



45
46
47
48
49
50
51
52
53
# File 'lib/duck_record/attribute_methods/dirty.rb', line 45

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(mutation_tracker.changed_values).freeze
  end
end

#changesObject



55
56
57
58
59
# File 'lib/duck_record/attribute_methods/dirty.rb', line 55

def changes
  cache_changed_attributes do
    super
  end
end

#changes_appliedObject



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

def changes_applied
  @previous_mutation_tracker = mutation_tracker
  @changed_attributes = HashWithIndifferentAccess.new
  store_original_attributes
end

#clear_attribute_changes(attr_names) ⇒ Object



38
39
40
41
42
43
# File 'lib/duck_record/attribute_methods/dirty.rb', line 38

def clear_attribute_changes(attr_names)
  super
  attr_names.each do |attr_name|
    clear_attribute_change(attr_name)
  end
end

#clear_changes_informationObject



26
27
28
29
30
# File 'lib/duck_record/attribute_methods/dirty.rb', line 26

def clear_changes_information
  @previous_mutation_tracker = nil
  @changed_attributes = HashWithIndifferentAccess.new
  store_original_attributes
end

#initialize_dup(other) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
# File 'lib/duck_record/attribute_methods/dirty.rb', line 12

def initialize_dup(other) # :nodoc:
  super
  @attributes = self.class._default_attributes.map do |attr|
    attr.with_value_from_user(@attributes.fetch_value(attr.name))
  end
  @mutation_tracker = nil
end

#previous_changesObject



61
62
63
# File 'lib/duck_record/attribute_methods/dirty.rb', line 61

def previous_changes
  previous_mutation_tracker.changes
end

#raw_write_attribute(attr_name) ⇒ Object



32
33
34
35
36
# File 'lib/duck_record/attribute_methods/dirty.rb', line 32

def raw_write_attribute(attr_name, *)
  result = super
  clear_attribute_change(attr_name)
  result
end