Class: Operandi::Settings::Step
- Inherits:
-
Object
- Object
- Operandi::Settings::Step
- Defined in:
- lib/operandi/settings/step.rb
Overview
Stores configuration for a single service step.
Created automatically when using the step DSL method.
Instance Attribute Summary collapse
-
#always ⇒ Boolean?
readonly
True if step runs even after errors/warnings.
-
#name ⇒ Symbol
readonly
The step name (method to call).
Instance Method Summary collapse
-
#initialize(name, service_class, opts = {}) ⇒ Step
constructor
Initialize a new step definition.
-
#run(instance) ⇒ Boolean
Execute the step on the given service instance.
Constructor Details
#initialize(name, service_class, opts = {}) ⇒ Step
Initialize a new step definition.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/operandi/settings/step.rb', line 23 def initialize(name, service_class, opts = {}) @name = name @service_class = service_class @if = opts[:if] @unless = opts[:unless] @always = opts[:always] if @if && @unless raise Operandi::Error, "#{service_class} `if` and `unless` cannot be specified " \ "for the step `#{name}` at the same time" end end |
Instance Attribute Details
#always ⇒ Boolean? (readonly)
Returns true if step runs even after errors/warnings.
12 13 14 |
# File 'lib/operandi/settings/step.rb', line 12 def always @always end |
#name ⇒ Symbol (readonly)
Returns the step name (method to call).
9 10 11 |
# File 'lib/operandi/settings/step.rb', line 9 def name @name end |
Instance Method Details
#run(instance) ⇒ Boolean
Execute the step on the given service instance.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/operandi/settings/step.rb', line 42 def run(instance) # rubocop:disable Naming/PredicateMethod return false unless run?(instance) unless instance.respond_to?(name, true) available_steps = @service_class.steps.keys.join(", ") = "Step method `#{name}` is not defined in #{@service_class}. " \ "Defined steps: [#{available_steps}]" raise Operandi::RuntimeError.new(, service: instance) end execute_with_callbacks(instance) true end |