Module: StateMachines::Sequel
- Defined in:
- lib/state_machines/sequel.rb,
lib/state_machines/sequel/version.rb,
lib/state_machines/sequel/spec_helpers.rb
Defined Under Namespace
Modules: SpecHelpers
Classes: CurrentActorAlreadySet, FailedTransition
Constant Summary
collapse
- VERSION =
"1.4.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.log_callback ⇒ Object
Proc called with [instance, level, message, params]. By default, logs to ‘instance.logger` if it instance responds to :logger. If structured_logging is true, the message will be an ’event’ without any dynamic info, if false, the params will be rendered into the message so are suitable for unstructured logging.
32
33
34
|
# File 'lib/state_machines/sequel.rb', line 32
def log_callback
@log_callback
end
|
.structured_logging ⇒ Object
Returns the value of attribute structured_logging.
26
27
28
|
# File 'lib/state_machines/sequel.rb', line 26
def structured_logging
@structured_logging
end
|
Class Method Details
.current_actor ⇒ Object
49
50
51
|
# File 'lib/state_machines/sequel.rb', line 49
def current_actor
return Thread.current[:sequel_state_machines_current_actor]
end
|
.log(instance, level, message, params) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/state_machines/sequel.rb', line 41
def log(instance, level, message, params)
if self.structured_logging
paramstr = params.map { |k, v| "#{k}=#{v}" }.join(" ")
message = "#{message} #{paramstr}"
end
self.log_callback[instance, level, message, params]
end
|
.reset_logging ⇒ Object
34
35
36
37
38
39
|
# File 'lib/state_machines/sequel.rb', line 34
def reset_logging
self.log_callback = lambda { |instance, level, msg, _params|
instance.respond_to?(:logger) ? instance.logger.send(level, msg) : nil
}
self.structured_logging = false
end
|
.set_current_actor(admin, &block) ⇒ Object
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/state_machines/sequel.rb', line 53
def set_current_actor(admin, &block)
raise CurrentActorAlreadySet, "already set to: #{self.current_actor}" if !admin.nil? && !self.current_actor.nil?
Thread.current[:sequel_state_machines_current_actor] = admin
return if block.nil?
begin
yield
ensure
Thread.current[:sequel_state_machines_current_actor] = nil
end
end
|