Class: WorkflowTemplate::Outcome::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_template/outcome/block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(handler, binding) ⇒ Block

Returns a new instance of Block.



10
11
12
13
# File 'lib/workflow_template/outcome/block.rb', line 10

def initialize(handler, binding)
  @handler = handler
  @binding = binding
end

Instance Attribute Details

#handlerObject

Returns the value of attribute handler.



8
9
10
# File 'lib/workflow_template/outcome/block.rb', line 8

def handler
  @handler
end

Instance Method Details

#delegate_to(proc) ⇒ Object



43
44
45
# File 'lib/workflow_template/outcome/block.rb', line 43

def delegate_to(proc)
  instance_eval(&proc)
end

#error(match = nil, &block) ⇒ Object



23
24
25
# File 'lib/workflow_template/outcome/block.rb', line 23

def error(match = nil, &block)
  handle_status(:error, matcher: match, &block)
end

#invalid(&block) ⇒ Object



19
20
21
# File 'lib/workflow_template/outcome/block.rb', line 19

def invalid(&block)
  handle_status(:error, matcher: Validation::Result::Failure, &block)
end

#ok(&block) ⇒ Object



15
16
17
# File 'lib/workflow_template/outcome/block.rb', line 15

def ok(&block)
  handle_status(:ok, &block)
end

#otherwise(&block) ⇒ Object



27
28
29
# File 'lib/workflow_template/outcome/block.rb', line 27

def otherwise(&block)
  self.handler = handler.otherwise(binding: binding, &block)
end

#otherwise_raise(error: nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/workflow_template/outcome/block.rb', line 35

def otherwise_raise(error: nil)
  handler = handler()
  self.handler = handler.otherwise(binding: binding) do |_|
    error ||= Error.new("Unhandled workflow status: '#{handler.final_state.status}'")
    raise error
  end
end

#otherwise_unwrap(slice: nil, fetch: nil) ⇒ Object



31
32
33
# File 'lib/workflow_template/outcome/block.rb', line 31

def otherwise_unwrap(slice: nil, fetch: nil)
  self.handler = handler.otherwise_unwrap(slice: slice, fetch: fetch)
end