Module: Pathway::Plugins::Base::DSLMethods
- Defined in:
- lib/pathway.rb
Instance Method Summary collapse
- #guard(cond, &steps) ⇒ Object
- #initialize(operation, input) ⇒ Object
-
#map(callable) ⇒ Object
Execute step and replace the current state completely.
- #run(&bl) ⇒ Object
- #sequence(steps_wrapper, &steps) ⇒ Object
-
#set(callable, *args, to: @operation.result_key) ⇒ Object
Execute step and modify the former state setting the key.
-
#step(callable, *args) ⇒ Object
Execute step and preserve the former state.
Instance Method Details
#guard(cond, &steps) ⇒ Object
163 164 165 166 167 168 |
# File 'lib/pathway.rb', line 163 def guard(cond, &steps) cond = _callable(cond) sequence(-> seq, state { seq.call if cond.call(state) }, &steps) end |
#initialize(operation, input) ⇒ Object
123 124 125 126 |
# File 'lib/pathway.rb', line 123 def initialize(operation, input) @result = wrap(State.new(operation, input: input)) @operation = operation end |
#map(callable) ⇒ Object
Execute step and replace the current state completely
151 152 153 154 |
# File 'lib/pathway.rb', line 151 def map(callable) bl = _callable(callable) @result = @result.then(bl) end |
#run(&bl) ⇒ Object
128 129 130 131 |
# File 'lib/pathway.rb', line 128 def run(&bl) instance_eval(&bl) @result end |
#sequence(steps_wrapper, &steps) ⇒ Object
156 157 158 159 160 161 |
# File 'lib/pathway.rb', line 156 def sequence(steps_wrapper, &steps) @result.then do |state| seq = -> { @result = dup.run(&steps) } _callable(steps_wrapper).call(seq, state) end end |
#set(callable, *args, to: @operation.result_key) ⇒ Object
Execute step and modify the former state setting the key
141 142 143 144 145 146 147 148 |
# File 'lib/pathway.rb', line 141 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 |
#step(callable, *args) ⇒ Object
Execute step and preserve the former state
134 135 136 137 138 |
# File 'lib/pathway.rb', line 134 def step(callable, *args) bl = _callable(callable) @result = @result.tee { |state| bl.call(state, *args) } end |