Module: SeparateHistory::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/separate_history/model.rb

Instance Method Summary collapse

Instance Method Details

#all_historyObject

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)

Raises:

  • (ArgumentError)


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

Returns:

  • (Boolean)


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(timestamp)
  self.class.history_for(id, timestamp)
end

#latest_historyObject

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_historyObject

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