Module: Pathway::Plugins::Base::DSLMethods
- Defined in:
- lib/pathway.rb
Instance Method Summary collapse
- #around(execution_strategy, &steps) ⇒ Object (also: #sequence)
- #if_false(cond, &steps) ⇒ Object
- #if_true(cond, &steps) ⇒ Object (also: #guard)
- #initialize(state, operation) ⇒ Object
-
#map(callable) ⇒ Object
Execute step and replace the current state completely.
- #run(&steps) ⇒ Object
-
#set(callable, *args, to: @operation.result_key, **kwargs, &bl) ⇒ 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
193 194 195 196 197 198 199 |
# File 'lib/pathway.rb', line 193 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, &steps) ⇒ Object
206 207 208 |
# File 'lib/pathway.rb', line 206 def if_false(cond, &steps) if_true(_callable(cond) >> :!.to_proc, &steps) end |
#if_true(cond, &steps) ⇒ Object Also known as: guard
201 202 203 204 |
# File 'lib/pathway.rb', line 201 def if_true(cond, &steps) cond = _callable(cond) around(->(runner, state) { runner.call if cond.call(state) }, &steps) end |
#initialize(state, operation) ⇒ Object
149 150 151 |
# File 'lib/pathway.rb', line 149 def initialize(state, operation) @result, @operation = wrap(state), operation end |
#map(callable) ⇒ Object
Execute step and replace the current state completely
185 186 187 188 189 190 191 |
# File 'lib/pathway.rb', line 185 def map(callable,...) #:nocov: warn "[DEPRECATION] `Pathway::DSLMethods#map` has been deprecated, use `step` instead" #:nocov: bl = _callable(callable) @result = @result.then { |state| bl.call(state,...) } end |
#run(&steps) ⇒ Object
153 154 155 156 |
# File 'lib/pathway.rb', line 153 def run(&steps) instance_eval(&steps) @result end |
#set(callable, *args, to: @operation.result_key, **kwargs, &bl) ⇒ Object
Execute step and modify the former state setting the key
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/pathway.rb', line 170 def set(callable, *args, to: @operation.result_key, **kwargs, &bl) #:nocov: if block_given? warn "[DEPRECATION] Passing a block to the step method using `DSLMethods#set` is deprecated" end #:nocov: bl = _callable(callable) @result = @result.then do |state| wrap(bl.call(state, *args, **kwargs, &bl)) .then { |value| state.update(to => value) } end end |
#step(callable) ⇒ Object
Execute step and preserve the former state
159 160 161 162 163 164 165 166 167 |
# File 'lib/pathway.rb', line 159 def step(callable,...) #:nocov: if block_given? warn "[DEPRECATION] Passing a block to the step method using `DSLMethods#step` is deprecated" end #:nocov: bl = _callable(callable) @result = @result.tee { |state| bl.call(state,...) } end |