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
- #attribute_changed_in_place?(attr_name) ⇒ Boolean
- #changed_attributes ⇒ Object
- #changes ⇒ Object
- #changes_applied ⇒ Object
- #clear_attribute_changes(attr_names) ⇒ Object
- #clear_changes_information ⇒ Object
-
#initialize_dup(other) ⇒ Object
:nodoc:.
- #previous_changes ⇒ Object
- #raw_write_attribute(attr_name) ⇒ Object
Instance Method Details
#attribute_changed_in_place?(attr_name) ⇒ 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_attributes ⇒ Object
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 |
#changes ⇒ Object
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_applied ⇒ Object
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_information ⇒ Object
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_changes ⇒ Object
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 |