Class: Novel::WorkflowBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, repository:, raw_workflow: []) ⇒ WorkflowBuilder

Returns a new instance of WorkflowBuilder.



5
6
7
8
9
# File 'lib/novel/workflow_builder.rb', line 5

def initialize(name:, repository:, raw_workflow: [])
  @name = name
  @raw_workflow = raw_workflow
  @repository = repository
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/novel/workflow_builder.rb', line 3

def name
  @name
end

#raw_workflowObject (readonly)

Returns the value of attribute raw_workflow.



3
4
5
# File 'lib/novel/workflow_builder.rb', line 3

def raw_workflow
  @raw_workflow
end

#repositoryObject (readonly)

Returns the value of attribute repository.



3
4
5
# File 'lib/novel/workflow_builder.rb', line 3

def repository
  @repository
end

Instance Method Details

#buildObject



19
20
21
22
23
24
25
# File 'lib/novel/workflow_builder.rb', line 19

def build
  Saga.new(
    name: name,
    workflow: Workflow.new(raw: raw_workflow),
    executor: Executor.new(container: build_container, repository: repository)
  )
end

#register_step(name, activity:, compensation: nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/novel/workflow_builder.rb', line 11

def register_step(name, activity:, compensation: nil)
  self.class.new(
    name: name,
    repository: repository,
    raw_workflow: raw_workflow + [{ name: name, activity: activity, compensation: compensation }]
  )
end