Module: Dunlop::AttributeChangesTracking
- Extended by:
- ActiveSupport::Concern
- Included in:
- WorkflowStepModel
- Defined in:
- app/models/dunlop/attribute_changes_tracking.rb
Overview
Add tracking of last changed attributes. Models including this module will be able to track attribute changes like:
record.last_changed[:backup_created] #=> timestamp or nil
record.last_changed.backup_created #=> timestamp or nil
Defined Under Namespace
Modules: ClassMethods Classes: LastChanged
Instance Method Summary collapse
Instance Method Details
#last_changed ⇒ Object
24 25 26 |
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 24 def last_changed @last_changed ||= LastChanged.new(self) end |
#update_last_attribute_changed_at ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/dunlop/attribute_changes_tracking.rb', line 13 def update_last_attribute_changed_at changed_at = attribute_change_time || Time.now (changes.keys - self.class.ignore_attributes_for_last_change).each do |attr| if existing = last_attribute_changes.find{|changed| changed.attribute_name == attr } existing.update(changed_at: changed_at) else last_attribute_changes.create(changed_at: changed_at, attribute_name: attr) end end end |