Module: Operandi::Dsl::StepsDsl::ClassMethods
- Defined in:
- lib/operandi/dsl/steps_dsl.rb
Instance Method Summary collapse
-
#remove_step(name) ⇒ Object
Remove a step from the service.
-
#step(name, opts = {}) ⇒ Object
Define a step for the service.
-
#step_operations ⇒ Array
Get the list of step operations to be applied.
-
#steps ⇒ Hash
Get all steps including inherited ones.
-
#validate_steps! ⇒ Object
Validate that the service has steps defined Called before executing the service.
Instance Method Details
#remove_step(name) ⇒ Object
Remove a step from the service
79 80 81 82 83 84 |
# File 'lib/operandi/dsl/steps_dsl.rb', line 79 def remove_step(name) step_operations << { action: :remove, name: name } # Clear memoized steps since we're modifying them @steps = nil end |
#step(name, opts = {}) ⇒ Object
Define a step for the service
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/operandi/dsl/steps_dsl.rb', line 41 def step(name, opts = {}) # rubocop:disable Metrics/MethodLength Validation.validate_symbol_name!(name, :step, self) Validation.validate_reserved_name!(name, :step, self) Validation.validate_name_conflicts!(name, :step, self) validate_step_opts!(name, opts) # Build current steps to check for duplicates and find insertion targets current = steps if current.key?(name) raise Operandi::Error, "Step `#{name}` is already defined in service #{self}. Each step must have a unique name." end if (target = opts[:before] || opts[:after]) && !current.key?(target) available = current.keys.join(", ") raise Operandi::Error, "Cannot find target step `#{target}` in service #{self}. Available steps: [#{available}]" end step_obj = Settings::Step.new(name, self, opts) if opts[:before] || opts[:after] step_operations << { action: :insert, name: name, step: step_obj, before: opts[:before], after: opts[:after], } else step_operations << { action: :add, name: name, step: step_obj } end # Clear memoized steps since we're modifying them @steps = nil end |
#step_operations ⇒ Array
Get the list of step operations to be applied
96 97 98 |
# File 'lib/operandi/dsl/steps_dsl.rb', line 96 def step_operations @step_operations ||= [] end |
#steps ⇒ Hash
Get all steps including inherited ones
89 90 91 |
# File 'lib/operandi/dsl/steps_dsl.rb', line 89 def steps @steps ||= build_steps end |
#validate_steps! ⇒ Object
Validate that the service has steps defined Called before executing the service
104 105 106 107 108 109 |
# File 'lib/operandi/dsl/steps_dsl.rb', line 104 def validate_steps! return unless steps.empty? raise Operandi::NoStepsError, "Service #{self} has no steps defined. Define at least one step or implement a `run` method." end |