Module: Pathway::Plugins::Base::DSLMethods
- Defined in:
- lib/pathway.rb
Instance Method Summary collapse
- #around(wrapper, &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(&bl) ⇒ Object
-
#set(callable, *args, to: @operation.result_key) ⇒ Object
Execute step and modify the former state setting the key.
Instance Method Details
#around(wrapper, &steps) ⇒ Object Also known as: sequence
193 194 195 196 197 198 |
# File 'lib/pathway.rb', line 193 def around(wrapper, &steps) @result.then do |state| seq = -> (dsl = self) { @result = dsl.run(&steps) } _callable(wrapper).call(seq, state) end end |
#if_false(cond, &steps) ⇒ Object
207 208 209 210 |
# File 'lib/pathway.rb', line 207 def if_false(cond, &steps) cond = _callable(cond) if_true(-> state { !cond.call(state) }, &steps) end |
#if_true(cond, &steps) ⇒ Object Also known as: guard
200 201 202 203 204 205 |
# File 'lib/pathway.rb', line 200 def if_true(cond, &steps) cond = _callable(cond) around(-> seq, state { seq.call if cond.call(state) }, &steps) end |
#initialize(state, operation) ⇒ Object
161 162 163 |
# File 'lib/pathway.rb', line 161 def initialize(state, operation) @result, @operation = wrap(state), operation end |
#map(callable) ⇒ Object
Execute step and replace the current state completely
188 189 190 191 |
# File 'lib/pathway.rb', line 188 def map(callable) bl = _callable(callable) @result = @result.then(bl) end |
#run(&bl) ⇒ Object
165 166 167 168 |
# File 'lib/pathway.rb', line 165 def run(&bl) instance_eval(&bl) @result end |
#set(callable, *args, to: @operation.result_key) ⇒ Object
Execute step and modify the former state setting the key
178 179 180 181 182 183 184 185 |
# File 'lib/pathway.rb', line 178 def set(callable, *args, to: @operation.result_key) bl = _callable(callable) @result = @result.then do |state| wrap(bl.call(state, *args)) .then { |value| state.update(to => value) } end end |