Class: RubyReactor::Dsl::StepBuilder
- Inherits:
-
Object
- Object
- RubyReactor::Dsl::StepBuilder
- Includes:
- TemplateHelpers, ValidationHelpers
- Defined in:
- lib/ruby_reactor/dsl/step_builder.rb
Instance Attribute Summary collapse
-
#args_validator ⇒ Object
Returns the value of attribute args_validator.
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#compensate_block ⇒ Object
Returns the value of attribute compensate_block.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#guards ⇒ Object
Returns the value of attribute guards.
-
#impl ⇒ Object
Returns the value of attribute impl.
-
#name ⇒ Object
Returns the value of attribute name.
-
#output_validator ⇒ Object
Returns the value of attribute output_validator.
-
#retry_config ⇒ Object
Returns the value of attribute retry_config.
-
#run_block ⇒ Object
Returns the value of attribute run_block.
-
#undo_block ⇒ Object
Returns the value of attribute undo_block.
Instance Method Summary collapse
- #argument(name, source, transform: nil) ⇒ Object
- #async(async = true) ⇒ Object
- #build ⇒ Object
- #compensate(&block) ⇒ Object
- #guard(&guard_fn) ⇒ Object
-
#initialize(name, impl = nil, reactor = nil) ⇒ StepBuilder
constructor
A new instance of StepBuilder.
- #retries(max_attempts: 3, backoff: :exponential, base_delay: 1) ⇒ Object
- #run(&block) ⇒ Object
- #undo(&block) ⇒ Object
- #validate_args(schema_or_validator = nil, &block) ⇒ Object
- #validate_output(schema_or_validator = nil, &block) ⇒ Object
- #wait_for(*step_names) ⇒ Object
- #where(&predicate) ⇒ Object
Methods included from ValidationHelpers
Methods included from TemplateHelpers
#Failure, #Success, #element, #input, #result, #value
Constructor Details
#initialize(name, impl = nil, reactor = nil) ⇒ StepBuilder
Returns a new instance of StepBuilder.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 12 def initialize(name, impl = nil, reactor = nil) @name = name @impl = impl @reactor = reactor @arguments = {} @run_block = nil @compensate_block = nil @undo_block = nil @conditions = [] @guards = [] @dependencies = [] @args_validator = nil @output_validator = nil @async = false @retry_config = {} end |
Instance Attribute Details
#args_validator ⇒ Object
Returns the value of attribute args_validator.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def args_validator @args_validator end |
#arguments ⇒ Object
Returns the value of attribute arguments.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def arguments @arguments end |
#compensate_block ⇒ Object
Returns the value of attribute compensate_block.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def compensate_block @compensate_block end |
#conditions ⇒ Object
Returns the value of attribute conditions.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def conditions @conditions end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def dependencies @dependencies end |
#guards ⇒ Object
Returns the value of attribute guards.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def guards @guards end |
#impl ⇒ Object
Returns the value of attribute impl.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def impl @impl end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def name @name end |
#output_validator ⇒ Object
Returns the value of attribute output_validator.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def output_validator @output_validator end |
#retry_config ⇒ Object
Returns the value of attribute retry_config.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def retry_config @retry_config end |
#run_block ⇒ Object
Returns the value of attribute run_block.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def run_block @run_block end |
#undo_block ⇒ Object
Returns the value of attribute undo_block.
9 10 11 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 9 def undo_block @undo_block end |
Instance Method Details
#argument(name, source, transform: nil) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 29 def argument(name, source, transform: nil) @arguments[name] = { source: source, transform: transform } end |
#async(async = true) ⇒ Object
76 77 78 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 76 def async(async = true) @async = async end |
#build ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 88 def build step_config = { name: @name, impl: @impl, arguments: @arguments, run_block: @run_block, compensate_block: @compensate_block, undo_block: @undo_block, conditions: @conditions, guards: @guards, dependencies: @dependencies, args_validator: @args_validator, output_validator: @output_validator, async: @async, retry_config: @retry_config.empty? ? (@reactor&.retry_defaults || {}) : @retry_config } RubyReactor::Dsl::StepConfig.new(step_config) end |
#compensate(&block) ⇒ Object
40 41 42 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 40 def compensate(&block) @compensate_block = block end |
#guard(&guard_fn) ⇒ Object
52 53 54 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 52 def guard(&guard_fn) @guards << guard_fn end |
#retries(max_attempts: 3, backoff: :exponential, base_delay: 1) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 80 def retries(max_attempts: 3, backoff: :exponential, base_delay: 1) @retry_config = { max_attempts: max_attempts, backoff: backoff, base_delay: base_delay } end |
#run(&block) ⇒ Object
36 37 38 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 36 def run(&block) @run_block = block end |
#undo(&block) ⇒ Object
44 45 46 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 44 def undo(&block) @undo_block = block end |
#validate_args(schema_or_validator = nil, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 60 def validate_args(schema_or_validator = nil, &block) if block_given? @args_validator = build_input_validator(block) elsif schema_or_validator @args_validator = build_input_validator(schema_or_validator) end end |
#validate_output(schema_or_validator = nil, &block) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 68 def validate_output(schema_or_validator = nil, &block) if block_given? @output_validator = build_input_validator(block) elsif schema_or_validator @output_validator = build_input_validator(schema_or_validator) end end |
#wait_for(*step_names) ⇒ Object
56 57 58 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 56 def wait_for(*step_names) @dependencies.concat(step_names) end |
#where(&predicate) ⇒ Object
48 49 50 |
# File 'lib/ruby_reactor/dsl/step_builder.rb', line 48 def where(&predicate) @conditions << predicate end |