Class: StateMachine::AuditTrail::Backend::Mongoid

Inherits:
StateMachine::AuditTrail::Backend show all
Defined in:
lib/state_machine/audit_trail/backend/mongoid.rb

Overview

This is the class that does the actual logging. We need one of these per ORM

Instance Attribute Summary

Attributes inherited from StateMachine::AuditTrail::Backend

#owner_class, #transition_class

Instance Method Summary collapse

Methods inherited from StateMachine::AuditTrail::Backend

create_for_transition_class

Instance Method Details

#log(object, event, from, to, timestamp = Time.now) ⇒ Object

Public writes the log to the database

object: the object being watched by the state_machine observer event: the event being observed by the state machine from: the state of the object prior to the event to: the state of the object after the event



12
13
14
15
16
# File 'lib/state_machine/audit_trail/backend/mongoid.rb', line 12

def log(object, event, from, to, timestamp = Time.now)
  tc = transition_class
  foreign_key_field = tc.relations.keys.first
  transition_class.create(foreign_key_field => object, :event => event, :from => from, :to => to, :created_at => timestamp)
end