Class: StateMachine::AuditTrail::Backend
- Inherits:
-
Struct
- Object
- Struct
- StateMachine::AuditTrail::Backend
- Defined in:
- lib/state_machine/audit_trail/backend.rb
Direct Known Subclasses
Defined Under Namespace
Classes: ActiveRecord, Mongoid
Instance Attribute Summary collapse
-
#owner_class ⇒ Object
Returns the value of attribute owner_class.
-
#transition_class ⇒ Object
Returns the value of attribute transition_class.
Class Method Summary collapse
-
.create_for_transition_class(transition_class, owner_class, context_to_log = nil) ⇒ Object
Public creates an instance of the class which does the actual logging.
Instance Method Summary collapse
Instance Attribute Details
#owner_class ⇒ Object
Returns the value of attribute owner_class
1 2 3 |
# File 'lib/state_machine/audit_trail/backend.rb', line 1 def owner_class @owner_class end |
#transition_class ⇒ Object
Returns the value of attribute transition_class
1 2 3 |
# File 'lib/state_machine/audit_trail/backend.rb', line 1 def transition_class @transition_class end |
Class Method Details
.create_for_transition_class(transition_class, owner_class, context_to_log = nil) ⇒ Object
Public creates an instance of the class which does the actual logging
transition_class: the Class which holds the audit trail
in order to adda new ORM here, copy audit_trail/mongoid.rb to whatever you want to call the new file and implement the #log function there then, return from here the appropriate object based on which ORM the transition_class is using
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/state_machine/audit_trail/backend.rb', line 16 def self.create_for_transition_class(transition_class, owner_class, context_to_log = nil) if Object.const_defined?('ActiveRecord') && transition_class.ancestors.include?(::ActiveRecord::Base) return StateMachine::AuditTrail::Backend::ActiveRecord.new(transition_class, owner_class, context_to_log) elsif Object.const_defined?('Mongoid') && transition_class.ancestors.include?(::Mongoid::Document) # Mongoid implementation doesn't yet support additional context fields raise NotImplemented, "Mongoid does not support additional context fields" if context_to_log.present? return StateMachine::AuditTrail::Backend::Mongoid.new(transition_class, owner_class) else raise NotImplemented, "Only support for ActiveRecord and Mongoid is included at this time" end end |
Instance Method Details
#log(object, event, from, to, timestamp = Time.now) ⇒ Object
6 7 8 |
# File 'lib/state_machine/audit_trail/backend.rb', line 6 def log(object, event, from, to, = Time.now) raise NotImplemented, "Implement in a subclass." end |