module Historiographer::History

Public Instance Methods

destroy() click to toggle source

A History record should never be destroyed.

History records are immutable, so we enforce this constraint as much as we can at the Rails layer.

# File lib/historiographer/history.rb, line 124
def destroy
  false
end
destroy!() click to toggle source
# File lib/historiographer/history.rb, line 128
def destroy!
  false
end
history_foreign_key() click to toggle source

The foreign key to the primary class.

E.g. PostHistory.history_foreign_key => post_id

# File lib/historiographer/history.rb, line 165
def history_foreign_key
  name.gsub(/History$/) {}.foreign_key
end
save(*args) click to toggle source

History records should never be updated, except to set history_ended_at (when they are overridden by future histories).

If the record was already persisted, then they only change it is allowed to make is to history_ended_at.

If the record was not already persisted, proceed as normal.

Calls superclass method
# File lib/historiographer/history.rb, line 141
def save(*args)
  if persisted? && (changes.keys - %w(history_ended_at)).any?
    false
  else
    super
  end
end
save!(*args) click to toggle source
Calls superclass method
# File lib/historiographer/history.rb, line 149
def save!(*args)
  if persisted? && (changes.keys - %w(history_ended_at)).any?
    false
  else
    super
  end
end