module Arkaan::Concerns::Historizable::ClassMethods
Submodule holding all the static methods add to the current subclass. @author Vincent Courtois <courtois.vincent@outlook.com>
Public Instance Methods
historization_after_init(field)
click to toggle source
# File lib/arkaan/concerns/historizable.rb, line 47 def historization_after_init(field) after_initialize do |doc| add_history(field: field.name, from: nil, to: doc[field.name]) end end
historization_after_save(field)
click to toggle source
# File lib/arkaan/concerns/historizable.rb, line 53 def historization_after_save(field) after_save do |doc| if doc.changed_attributes.key?(field.name) from = doc.changed_attributes[field.name] add_history(field: field.name, from: from, to: doc[field.name]) end end end
historize(field)
click to toggle source
Takes the Mongoid declared field and creates the callbacks to intercept any value change and add it to the history. @field field [Mongoid::Fields::Standard] the Mongoid field to historize.
# File lib/arkaan/concerns/historizable.rb, line 41 def historize(field) embeds_many :history, class_name: 'Arkaan::Event' unless relations.key?('history') historization_after_init(field) historization_after_save(field) end