Module: Workflows

Included in:
Example::Signup::SignupWorkflow
Defined in:
lib/workflows.rb,
lib/workflows/step.rb,
lib/workflows/version.rb,
lib/workflows/step_service.rb

Defined Under Namespace

Modules: ClassMethods, StepService Classes: Step

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/workflows.rb', line 6

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#initialize(service_args = {}) ⇒ Object

instance methods



24
25
26
27
28
29
30
31
32
# File 'lib/workflows.rb', line 24

def initialize(service_args = {})
  # TODO: validate service_args
  # make sure there is one for each service
  # according to the wf structure defined with has_flow
  wf_steps.each do |wf_step|
    args = service_args.fetch(wf_step.name.to_sym)
    wf_step.set_args args
  end
end

#outputObject



53
54
55
# File 'lib/workflows.rb', line 53

def output
  wf_steps.map { |wf_step| wf_step.output }
end

#run(args = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/workflows.rb', line 34

def run(args = {})
  previous_state = {}
  wf_steps.each do |wf_step|
    wf_step.set_state(previous_state)
    wf_step.run
    previous_state = wf_step.get_state
  end

  wf_steps.last.get_output
end

#stateObject



45
46
47
# File 'lib/workflows.rb', line 45

def state
  wf_steps.last.get_state
end

#statusObject



49
50
51
# File 'lib/workflows.rb', line 49

def status
  wf_steps.map { |wf_step| wf_step.status }
end