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
165 166 167 168 169 170 |
# File 'lib/pathway.rb', line 165 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
179 180 181 182 |
# File 'lib/pathway.rb', line 179 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
172 173 174 175 176 177 |
# File 'lib/pathway.rb', line 172 def if_true(cond, &steps) cond = _callable(cond) around(-> seq, state { seq.call if cond.call(state) }, &steps) end |
#initialize(state, operation) ⇒ Object
133 134 135 |
# File 'lib/pathway.rb', line 133 def initialize(state, operation) @result, @operation = wrap(state), operation end |
#map(callable) ⇒ Object
Execute step and replace the current state completely
160 161 162 163 |
# File 'lib/pathway.rb', line 160 def map(callable) bl = _callable(callable) @result = @result.then(bl) end |
#run(&bl) ⇒ Object
137 138 139 140 |
# File 'lib/pathway.rb', line 137 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
150 151 152 153 154 155 156 157 |
# File 'lib/pathway.rb', line 150 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 |