Class: WorkflowRb::StepBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow_rb/services/workflow_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(workflow_builder, step) ⇒ StepBuilder

Returns a new instance of StepBuilder.



55
56
57
58
# File 'lib/workflow_rb/services/workflow_builder.rb', line 55

def initialize(workflow_builder, step)
  @workflow_builder = workflow_builder
  @step = step
end

Instance Attribute Details

#stepObject

Returns the value of attribute step.



53
54
55
# File 'lib/workflow_rb/services/workflow_builder.rb', line 53

def step
  @step
end

Instance Method Details

#input(step_property, &value) ⇒ Object

Map workflow instance data to a property on the step

Parameters:

  • step_property (Symbol)

    the attribute on the step body class



105
106
107
108
109
110
111
# File 'lib/workflow_rb/services/workflow_builder.rb', line 105

def input(step_property, &value)
  mapping = IOMapping.new
  mapping.property = step_property
  mapping.value = value
  @step.inputs << mapping
  self
end

#name(name) ⇒ Object



60
61
62
# File 'lib/workflow_rb/services/workflow_builder.rb', line 60

def name(name)
  @step.name = name
end

#output(data_property, &value) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/workflow_rb/services/workflow_builder.rb', line 113

def output(data_property, &value)
  mapping = IOMapping.new
  mapping.property = data_property
  mapping.value = value
  @step.outputs << mapping
  self
end

#then(body, &setup) ⇒ Object

Adds a new step to the workflow

Parameters:

  • body (Class)

    the step body implementation class



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/workflow_rb/services/workflow_builder.rb', line 67

def then(body, &setup)
  new_step = WorkflowStep.new
  new_step.body = body

  @workflow_builder.add_step(new_step)
  new_builder = StepBuilder.new(@workflow_builder, new_step)

  if body.kind_of?(Class)
    new_step.name = body.name
  end

  if setup
    setup.call(new_builder)
  end

  new_outcome = StepOutcome.new
  new_outcome.next_step = new_step.id
  new_outcome.value = nil
  @step.outcomes << new_outcome

  new_builder
end

#then_step(&body) ⇒ Object



90
91
92
# File 'lib/workflow_rb/services/workflow_builder.rb', line 90

def then_step(&body)
  self.then(body)
end

#wait_for(event_name, event_key) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/workflow_rb/services/workflow_builder.rb', line 121

def wait_for(event_name, event_key)
  new_step = SubscriptionStep.new
  new_step.event_name = event_name
  new_step.event_key = event_key

  @workflow_builder.add_step(new_step)
  new_builder = StepBuilder.new(@workflow_builder, new_step)
  new_step.name = 'WaitFor'

  new_outcome = StepOutcome.new
  new_outcome.next_step = new_step.id
  new_outcome.value = nil
  @step.outcomes << new_outcome

  new_builder
end

#when(value) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/workflow_rb/services/workflow_builder.rb', line 94

def when(value)
  new_outcome = StepOutcome.new
  new_outcome.value = value
  @step.outcomes << new_outcome
  new_builder = OutcomeBuilder.new(@workflow_builder, new_outcome)
  new_builder
end