Class: StateMachine::AuditTrail::Backend

Inherits:
Struct
  • Object
show all
Defined in:
lib/state_machine/audit_trail/backend.rb

Direct Known Subclasses

ActiveRecord, Mongoid

Defined Under Namespace

Classes: ActiveRecord, Mongoid

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#owner_classObject

Returns the value of attribute owner_class

Returns:

  • (Object)

    the current value of owner_class



1
2
3
# File 'lib/state_machine/audit_trail/backend.rb', line 1

def owner_class
  @owner_class
end

#transition_classObject

Returns the value of attribute transition_class

Returns:

  • (Object)

    the current value of 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

Raises:

  • (NotImplemented)


6
7
8
# File 'lib/state_machine/audit_trail/backend.rb', line 6

def log(object, event, from, to, timestamp = Time.now)
  raise NotImplemented, "Implement in a subclass."
end