Module: Intercom::Traits::DirtyTracking
- Included in:
- ApiResource
- Defined in:
- lib/intercom/traits/dirty_tracking.rb
Instance Method Summary collapse
- #field_changed?(field_name) ⇒ Boolean
- #instance_variables_excluding_dirty_tracking_field ⇒ Object
- #mark_field_as_changed!(field_name) ⇒ Object
- #mark_fields_as_changed!(field_names) ⇒ Object
- #reset_changed_fields! ⇒ Object
Instance Method Details
#field_changed?(field_name) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/intercom/traits/dirty_tracking.rb', line 23 def field_changed?(field_name) @changed_fields ||= Set.new field = instance_variable_get("@#{field_name}") if field.respond_to?(:field_changed?) field.to_hash.any? do |attribute, _| field.field_changed?(attribute) end else @changed_fields.include?(field_name.to_s) end end |
#instance_variables_excluding_dirty_tracking_field ⇒ Object
35 36 37 |
# File 'lib/intercom/traits/dirty_tracking.rb', line 35 def instance_variables_excluding_dirty_tracking_field instance_variables.reject{|var| var == :@changed_fields} end |
#mark_field_as_changed!(field_name) ⇒ Object
18 19 20 21 |
# File 'lib/intercom/traits/dirty_tracking.rb', line 18 def mark_field_as_changed!(field_name) @changed_fields ||= Set.new @changed_fields.add(field_name.to_s) end |
#mark_fields_as_changed!(field_names) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/intercom/traits/dirty_tracking.rb', line 11 def mark_fields_as_changed!(field_names) @changed_fields ||= Set.new field_names.each do |attr| @changed_fields.add(attr.to_s) end end |
#reset_changed_fields! ⇒ Object
7 8 9 |
# File 'lib/intercom/traits/dirty_tracking.rb', line 7 def reset_changed_fields! @changed_fields = Set.new end |