Class: Smith::Workflow::Pipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/smith/workflow/pipeline.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, from:, to:) ⇒ Pipeline

Returns a new instance of Pipeline.

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/smith/workflow/pipeline.rb', line 8

def initialize(name, from:, to:, &)
  raise WorkflowError, "pipeline name is required" if name.nil?
  raise WorkflowError, "pipeline :#{name} requires from:" if from.nil?
  raise WorkflowError, "pipeline :#{name} requires to:" if to.nil?

  @name = name
  @from = from
  @to = to
  @stages = []
  @failure_transition = nil
  instance_eval(&)
end

Instance Attribute Details

#failure_transitionObject (readonly)

Returns the value of attribute failure_transition.



6
7
8
# File 'lib/smith/workflow/pipeline.rb', line 6

def failure_transition
  @failure_transition
end

#fromObject (readonly)

Returns the value of attribute from.



6
7
8
# File 'lib/smith/workflow/pipeline.rb', line 6

def from
  @from
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/smith/workflow/pipeline.rb', line 6

def name
  @name
end

#stagesObject (readonly)

Returns the value of attribute stages.



6
7
8
# File 'lib/smith/workflow/pipeline.rb', line 6

def stages
  @stages
end

#toObject (readonly)

Returns the value of attribute to.



6
7
8
# File 'lib/smith/workflow/pipeline.rb', line 6

def to
  @to
end

Instance Method Details

#compile!(workflow_class) ⇒ Object



32
33
34
35
36
# File 'lib/smith/workflow/pipeline.rb', line 32

def compile!(workflow_class)
  validate!
  validate_no_collisions!(workflow_class)
  generate_transitions(workflow_class)
end

#on_failure(transition_name) ⇒ Object



28
29
30
# File 'lib/smith/workflow/pipeline.rb', line 28

def on_failure(transition_name)
  @failure_transition = transition_name
end

#stage(stage_name, execute:) ⇒ Object

Raises:



21
22
23
24
25
26
# File 'lib/smith/workflow/pipeline.rb', line 21

def stage(stage_name, execute:)
  raise WorkflowError, "pipeline :#{name} stage name is required" if stage_name.nil?
  raise WorkflowError, "pipeline :#{name} stage :#{stage_name} requires execute:" if execute.nil?

  @stages << { name: stage_name, agent: execute }
end