Module: Historiographer
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/historiographer.rb,
lib/historiographer/safe.rb,
lib/historiographer/silent.rb,
lib/historiographer/history.rb,
lib/historiographer/relation.rb,
lib/historiographer/history_migration.rb,
lib/historiographer/history_migration_mysql.rb
Overview
See Historiographer for more details
Historiographer::History is a mixin that is automatically included in any History class (e.g. RetailerProductHistory).
A History record represents a snapshot of a primary record at a particular point in time.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
E.g. You have a RetailerProduct (ID: 1) that makes the following changes:
1) rp = RetailerProduct.create(name: “Sabra”)
2) rp.update(name: “Sabra Hummus”)
3) rp.update(name: “Sabra Pine Nut Hummus”)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Your RetailerProduct record looks like this:
<#RetailerProduct:0x007fbf00c78f00 name: “Sabra Pine Nut Hummus”>
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
But your RetailerProductHistories look like this:
rp.histories
<#RetailerProductHistory:0x007fbf00c78f01 name: “Sabra”, history_started_at: 1.minute.ago, history_ended_at: 30.seconds.ago> <#RetailerProductHistory:0x007fbf00c78f02 name: “Sabra Hummus”, history_started_at: 30.seconds.ago, history_ended_at: 10.seconds.ago> <#RetailerProductHistory:0x007fbf00c78f03 name: “Sabra Pine Nut Hummus”, history_started_at: 10.seconds.ago, history_ended_at: nil>
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Since these Histories are intended to represent a snapshot in time, they should never be deleted or modified directly. Historiographer will manage all of the nuances for you.
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Your classes should be written like this:
class RetailerProduct < ActiveRecord::Base
include Historiographer
end
# This class is created automatically. You don’t # need to create a file yourself, unless you # want to add additional methods. # class RetailerProductHistory < ActiveRecord::Base
include Historiographer::History
end
Defined Under Namespace
Modules: History, HistoryMigration, HistoryMigrationMysql, Relation, Safe, Silent Classes: HistoryUserIdMissingError
Constant Summary collapse
- UTC =
Time.now.in_time_zone('UTC').time_zone