module SequentialWorkflow

Constants

VERSION

Attributes

workflow_state[RW]

Public Instance Methods

catch(catch_with) click to toggle source
# File lib/sequential_workflow.rb, line 14
def catch(catch_with)
  method(catch_with).call(@reason) if rejected?
end
fulfill(value) click to toggle source
# File lib/sequential_workflow.rb, line 31
def fulfill(value)
  @workflow_state = :fulfilled
  @value = value
  self
end
reject(e) click to toggle source
# File lib/sequential_workflow.rb, line 37
def reject(e)
  @workflow_state = :rejected
  @reason = e
  self
end
rejected?() click to toggle source
# File lib/sequential_workflow.rb, line 43
def rejected?
  @workflow_state == :rejected
end
start(initial_method) click to toggle source
# 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 = nil) click to toggle source
# File lib/sequential_workflow.rb, line 18
def then(on_success, rescue_with = nil)
  case workflow_state
  when :fulfilled
    result = method(on_success).call(@value)
    fulfill result
  when :rejected
    method(rescue_with).call(@reason) if rescue_with
    self
  end
rescue => e
  reject e
end