module StateGate::Engine::Errator
Description¶ ↑
Adds error reporting methods to a StateMachine::Engine
-
all error messages are I18n configured
-
method names are deliberately short to encourage code readability with if/unless one-liners
Private Instance Methods
aerr(err, **args)
click to toggle source
Report an ArgumentError, including the Klass#attr variable.
# File lib/state_gate/engine/errator.rb, line 55 def aerr(err, **args) args[:kattr] = "#{@klass}##{@attribute}" if args[:kattr] == true key = "state_gate.engine.#{err}" fail ArgumentError, I18n.t(key, **args) end
cerr(err, **args)
click to toggle source
Report a ConfigurationError
, including the Klass#attr variable.
# File lib/state_gate/engine/errator.rb, line 35 def cerr(err, **args) args[:kattr] = "#{@klass}##{@attribute}" if args[:kattr] == true key = "state_gate.engine.config.#{err}" fail ConfigurationError, I18n.t(key, **args) end
invalid_state_error(val)
click to toggle source
Format the given value and report an ArgumentError
# File lib/state_gate/engine/errator.rb, line 20 def invalid_state_error(val) case val when NilClass aerr :invalid_state_err, val: "'nil'", kattr: true when Symbol aerr :invalid_state_err, val: ":#{val}", kattr: true else aerr :invalid_state_err, val: "'#{val&.to_s}'", kattr: true end end
rerr(err, **args)
click to toggle source
Report a RuntimeError, including the Klass#attr variable.
# File lib/state_gate/engine/errator.rb, line 45 def rerr(err, **args) args[:kattr] = "#{@klass}##{@attribute}" if args[:kattr] == true key = "state_gate.engine.#{err}" fail I18n.t(key, **args) end