Class: RailsWorkflow::OperationBuilder
- Inherits:
-
Object
- Object
- RailsWorkflow::OperationBuilder
- Defined in:
- lib/rails_workflow/operation_builder.rb
Overview
Operation builder which creates new operaitons including their context, child processes etc… s
Instance Attribute Summary collapse
-
#completed_dependencies ⇒ Object
Returns the value of attribute completed_dependencies.
-
#process ⇒ Object
Returns the value of attribute process.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #after_operation_create(operation) ⇒ Object
- #create_operation ⇒ Object
- #create_operation! ⇒ Object
-
#initialize(process, template, completed_dependencies = []) ⇒ OperationBuilder
constructor
A new instance of OperationBuilder.
- #prepared_dependencies ⇒ Object
Constructor Details
#initialize(process, template, completed_dependencies = []) ⇒ OperationBuilder
Returns a new instance of OperationBuilder.
10 11 12 13 14 |
# File 'lib/rails_workflow/operation_builder.rb', line 10 def initialize(process, template, completed_dependencies = []) @process = process @template = template @completed_dependencies = completed_dependencies end |
Instance Attribute Details
#completed_dependencies ⇒ Object
Returns the value of attribute completed_dependencies.
7 8 9 |
# File 'lib/rails_workflow/operation_builder.rb', line 7 def completed_dependencies @completed_dependencies end |
#process ⇒ Object
Returns the value of attribute process.
7 8 9 |
# File 'lib/rails_workflow/operation_builder.rb', line 7 def process @process end |
#template ⇒ Object
Returns the value of attribute template.
7 8 9 |
# File 'lib/rails_workflow/operation_builder.rb', line 7 def template @template end |
Instance Method Details
#after_operation_create(operation) ⇒ Object
35 36 37 38 |
# File 'lib/rails_workflow/operation_builder.rb', line 35 def after_operation_create(operation) return unless template.respond_to?(:after_operation_create) template.after_operation_create(operation) end |
#create_operation ⇒ Object
16 17 18 19 20 |
# File 'lib/rails_workflow/operation_builder.rb', line 16 def create_operation create_operation!.tap { |operation| process.operations << operation } rescue => exception handle_exception(exception) end |
#create_operation! ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails_workflow/operation_builder.rb', line 22 def create_operation! operation = operation_class.create(prepared_attributes) do |new_operation| new_operation.context = build_context( new_operation, completed_dependencies ) after_operation_create(new_operation) end build_child_process(operation) operation end |
#prepared_dependencies ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rails_workflow/operation_builder.rb', line 40 def prepared_dependencies completed_dependencies.map do |dep| { operation_id: dep.id, status: dep.status } end end |