Module: TrackChanges::Model::ClassMethods
- Defined in:
- lib/track_changes/model.rb
Instance Method Summary collapse
-
#snapshot_all ⇒ Object
Create snapshots for all records so that the next changes made are captured This can be used to init track changes on existing records.
-
#track_changes_fields ⇒ Object
Returns the method names to call to fetch the fields tracked for changes.
Instance Method Details
#snapshot_all ⇒ Object
Create snapshots for all records so that the next changes made are captured This can be used to init track changes on existing records
33 34 35 36 37 38 |
# File 'lib/track_changes/model.rb', line 33 def snapshot_all # Update existing snapshots joins(:snapshot).find_each {|record| record.snapshot.update } # Create new snapshots where.not(:id => joins(:snapshot)).find_each(&:create_snapshot) end |
#track_changes_fields ⇒ Object
Returns the method names to call to fetch the fields tracked for changes
23 24 25 26 27 28 29 |
# File 'lib/track_changes/model.rb', line 23 def track_changes_fields fields = Array([:only]).collect(&:to_s).presence || self.attribute_names fields -= Array([:except]).collect(&:to_s) fields += Array([:methods]).collect(&:to_s) fields -= ['created_at', 'updated_at'] unless [:track_timestamps] fields -= [primary_key] unless [:track_primary_key] end |