Module: Pathway::Plugins::Base::DSLMethods
- Defined in:
- lib/pathway.rb
Instance Method Summary collapse
- #around(execution_strategy, &steps) ⇒ Object (also: #sequence)
- #if_false(cond) ⇒ Object
- #if_true(cond) ⇒ Object (also: #guard)
- #initialize(state, operation) ⇒ Object
- #run ⇒ Object
-
#set(callable, *args, to: @operation.result_key, **kwargs) ⇒ Object
Execute step and modify the former state setting the key.
-
#step(callable) ⇒ Object
Execute step and preserve the former state.
Instance Method Details
#around(execution_strategy, &steps) ⇒ Object Also known as: sequence
176 177 178 179 180 181 182 |
# File 'lib/pathway.rb', line 176 def around(execution_strategy, &steps) @result.then do |state| steps_runner = ->(dsl = self) { dsl.run(&steps) } _callable(execution_strategy).call(steps_runner, state) end end |
#if_false(cond) ⇒ Object
189 190 191 |
# File 'lib/pathway.rb', line 189 def if_false(cond, &) if_true(_callable(cond) >> :!.to_proc, &) end |
#if_true(cond) ⇒ Object Also known as: guard
184 185 186 187 |
# File 'lib/pathway.rb', line 184 def if_true(cond, &) cond = _callable(cond) around(->(runner, state) { runner.call if cond.call(state) }, &) end |
#initialize(state, operation) ⇒ Object
151 152 153 |
# File 'lib/pathway.rb', line 151 def initialize(state, operation) @result, @operation = wrap(state), operation end |
#run ⇒ Object
155 156 157 158 |
# File 'lib/pathway.rb', line 155 def run(&) instance_eval(&) @result end |
#set(callable, *args, to: @operation.result_key, **kwargs) ⇒ Object
Execute step and modify the former state setting the key
167 168 169 170 171 172 173 174 |
# File 'lib/pathway.rb', line 167 def set(callable, *args, to: @operation.result_key, **kwargs) bl = _callable(callable) @result = @result.then do |state| wrap(bl.call(state, *args, **kwargs)) .then { |value| state.update(to => value) } end end |
#step(callable) ⇒ Object
Execute step and preserve the former state
161 162 163 164 |
# File 'lib/pathway.rb', line 161 def step(callable, *, **) bl = _callable(callable) @result = @result.tee { |state| bl.call(state, *, **) } end |