Module: SeparateHistory::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/separate_history/model.rb
Instance Method Summary collapse
-
#all_history ⇒ Object
Get all historical versions of this record.
-
#clear_history(force:) ⇒ Object
Delete this record’s history (requires force: true).
-
#history? ⇒ Boolean
Check if any history exists for this instance.
-
#history_as_of(timestamp) ⇒ Object
Get the snapshot of this record at or before the given timestamp.
-
#latest_history ⇒ Object
Get the latest snapshot of this record.
-
#snapshot_history ⇒ Object
Manually create a history snapshot for this record.
Instance Method Details
#all_history ⇒ Object
Get all historical versions of this record
25 26 27 |
# File 'lib/separate_history/model.rb', line 25 def all_history self.class.all_history_for(id) end |
#clear_history(force:) ⇒ Object
Delete this record’s history (requires force: true)
35 36 37 38 39 |
# File 'lib/separate_history/model.rb', line 35 def clear_history(force:) raise ArgumentError, "Force must be true to clear history." unless force self.class.history_class.where(original_id: id).delete_all end |
#history? ⇒ Boolean
Check if any history exists for this instance
15 16 17 |
# File 'lib/separate_history/model.rb', line 15 def history? self.class.history_class.where(original_id: id).exists? end |
#history_as_of(timestamp) ⇒ Object
Get the snapshot of this record at or before the given timestamp
20 21 22 |
# File 'lib/separate_history/model.rb', line 20 def history_as_of() self.class.history_for(id, ) end |
#latest_history ⇒ Object
Get the latest snapshot of this record
30 31 32 |
# File 'lib/separate_history/model.rb', line 30 def latest_history self.class.latest_history_for(id) end |
#snapshot_history ⇒ Object
Manually create a history snapshot for this record
10 11 12 |
# File 'lib/separate_history/model.rb', line 10 def snapshot_history _create_history_record("snapshot") end |