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
70 71 72 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 70 def attribute_changed_in_place?(attr_name) mutation_tracker.changed_in_place?(attr_name) end |
#changed_attributes ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 50 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
60 61 62 63 64 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 60 def changes cache_changed_attributes do super end end |
#changes_applied ⇒ Object
25 26 27 28 29 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 25 def changes_applied @previous_mutation_tracker = mutation_tracker @changed_attributes = HashWithIndifferentAccess.new store_original_attributes end |
#clear_attribute_changes(attr_names) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 43 def clear_attribute_changes(attr_names) super attr_names.each do |attr_name| clear_attribute_change(attr_name) end end |
#clear_changes_information ⇒ Object
31 32 33 34 35 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 31 def clear_changes_information @previous_mutation_tracker = nil @changed_attributes = HashWithIndifferentAccess.new store_original_attributes end |
#initialize_dup(other) ⇒ Object
:nodoc:
17 18 19 20 21 22 23 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 17 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
66 67 68 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 66 def previous_changes previous_mutation_tracker.changes end |
#raw_write_attribute(attr_name) ⇒ Object
37 38 39 40 41 |
# File 'lib/duck_record/attribute_methods/dirty.rb', line 37 def raw_write_attribute(attr_name, *) result = super clear_attribute_change(attr_name) result end |