Class: StateMachine::AuditTrail::Backend::ActiveRecord
- Inherits:
-
StateMachine::AuditTrail::Backend
- Object
- Struct
- StateMachine::AuditTrail::Backend
- StateMachine::AuditTrail::Backend::ActiveRecord
- Defined in:
- lib/state_machine/audit_trail/backend/active_record.rb
Instance Attribute Summary collapse
-
#context_to_log ⇒ Object
Returns the value of attribute context_to_log.
Attributes inherited from StateMachine::AuditTrail::Backend
#owner_class, #transition_class
Instance Method Summary collapse
-
#initialize(transition_class, owner_class, context_to_log = nil) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
- #log(object, event, from, to, timestamp = Time.now) ⇒ Object
Methods inherited from StateMachine::AuditTrail::Backend
Constructor Details
#initialize(transition_class, owner_class, context_to_log = nil) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
4 5 6 7 8 9 |
# File 'lib/state_machine/audit_trail/backend/active_record.rb', line 4 def initialize(transition_class, owner_class, context_to_log = nil) self.context_to_log = context_to_log @association = transition_class.to_s.tableize.to_sym super transition_class owner_class.has_many @association end |
Instance Attribute Details
#context_to_log ⇒ Object
Returns the value of attribute context_to_log.
2 3 4 |
# File 'lib/state_machine/audit_trail/backend/active_record.rb', line 2 def context_to_log @context_to_log end |
Instance Method Details
#log(object, event, from, to, timestamp = Time.now) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/state_machine/audit_trail/backend/active_record.rb', line 11 def log(object, event, from, to, = Time.now) # Let ActiveRecord manage the timestamp for us so it does the # right thing with regards to timezones. params = {:event => event, :from => from, :to => to} params[self.context_to_log] = object.send(self.context_to_log) unless self.context_to_log.nil? object.send(@association).create(params) end |