Class: RWF::Flow
- Inherits:
-
Object
- Object
- RWF::Flow
- Defined in:
- lib/rwf/flow.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
i[type cure ptr on_success on_error].freeze
Class Method Summary collapse
- .call(io_params = {}, params = nil) ⇒ Object
- .cure(*args) ⇒ Object
- .error(*args) ⇒ Object
- .task(*args) ⇒ Object
- .tasks ⇒ Object
Instance Method Summary collapse
Class Method Details
.call(io_params = {}, params = nil) ⇒ Object
32 33 34 |
# File 'lib/rwf/flow.rb', line 32 def call(io_params = {}, params = nil) new.(io_params, params) end |
.cure(*args) ⇒ Object
24 25 26 |
# File 'lib/rwf/flow.rb', line 24 def cure(*args) error(*args, cure: true) end |
.error(*args) ⇒ Object
28 29 30 |
# File 'lib/rwf/flow.rb', line 28 def error(*args) task(*args, type: :error) end |
.task(*args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rwf/flow.rb', line 12 def task(*args) task, * = *args = {} .each { |option| .merge!(option) } [:ptr] ||= task if task.is_a?(Symbol) = .keys - ALLOWED_OPTIONS raise ConfigError, "Unknown task option(s): #{extra_options.join(',')}." unless .empty? tasks << [task, ] end |
.tasks ⇒ Object
8 9 10 |
# File 'lib/rwf/flow.rb', line 8 def tasks @tasks ||= [] end |
Instance Method Details
#call(io_params = {}, params = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rwf/flow.rb', line 41 def call(io_params = {}, params = nil) result = Result.new(io_params) next_type = nil next_ptr = nil next_index = 0 while next_index < tasks.size task, = tasks[next_index] if [:type] == next_type || next_ptr next_type, next_ptr = execute_task(result, task, , io_params, params) break if next_ptr == :end end next_index = decide_index(next_index, next_ptr) end result.initial? ? result.success! : result end |
#tasks ⇒ Object
37 38 39 |
# File 'lib/rwf/flow.rb', line 37 def tasks self.class.tasks end |