Module: SequentialWorkflow

Defined in:
lib/sequential_workflow.rb,
lib/sequential_workflow/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workflow_stateObject

Returns the value of attribute workflow_state.



5
6
7
# File 'lib/sequential_workflow.rb', line 5

def workflow_state
  @workflow_state
end

Instance Method Details

#failObject



41
42
43
44
# File 'lib/sequential_workflow.rb', line 41

def fail
  @workflow_state = :failed
  self
end

#fulfill(value) ⇒ Object



29
30
31
32
33
# File 'lib/sequential_workflow.rb', line 29

def fulfill(value)
  @workflow_state = :fulfilled
  @value = value
  self
end

#reject(e) ⇒ Object



35
36
37
38
39
# File 'lib/sequential_workflow.rb', line 35

def reject(e)
  @workflow_state = :rejected
  @reason = e
  self
end

#start(initial_method) ⇒ Object



7
8
9
10
11
12
# File 'lib/sequential_workflow.rb', line 7

def start(initial_method)
  result = method(initial_method).call
  fulfill result
rescue => e
  reject(e)
end

#then(on_success, rescue_with) ⇒ Object Also known as: end_with



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sequential_workflow.rb', line 14

def then(on_success, rescue_with)
  case workflow_state
  when :fulfilled
    result = method(on_success).call(@value)
    fulfill result
  when :rejected
    method(rescue_with).call(@reason)
    fail
  when :failed
    self
  end
rescue => e
  reject(e)
end