class RailsWorkflow::OperationBuilder
Operation builder which creates new operaitons including their context, child processes etc… s
Attributes
completed_dependencies[RW]
process[RW]
template[RW]
Public Class Methods
new(process, template, completed_dependencies = [])
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 10 def initialize(process, template, completed_dependencies = []) @process = process @template = template @completed_dependencies = completed_dependencies end
Public Instance Methods
after_operation_create(operation)
click to toggle source
# 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()
click to toggle source
# 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!()
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
build_child_process(operation)
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 62 def build_child_process(operation) return unless child_process.present? # TODO: replace with Process Builder or replace with # config process manager operation.child_process = RailsWorkflow::ProcessManager .create_process( child_process.id, operation.context.data ) end
build_context(operation, dependencies)
click to toggle source
TODO: move to ContextBuilder
# File lib/rails_workflow/operation_builder.rb, line 79 def build_context(operation, dependencies) RailsWorkflow::Context.new( parent: operation, data: prepare_context_data(dependencies) || operation.process.data ) end
config()
click to toggle source
TODO: move config
# File lib/rails_workflow/operation_builder.rb, line 99 def config RailsWorkflow.config end
error_builder()
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 94 def error_builder config.error_builder end
handle_exception(exception)
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 86 def handle_exception(exception) error_builder.handle( exception, parent: process, target: :operation_builder, method: :create_operation, args: [process, template, completed_dependencies] ) end
prepare_context_data(dependencies)
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 74 def prepare_context_data(dependencies) dependencies.first.try(:context).try(:data) end
prepared_attributes()
click to toggle source
# File lib/rails_workflow/operation_builder.rb, line 51 def prepared_attributes attributes.with_indifferent_access .slice(:title, :async, :is_background) .merge(template: template, tag: template.tag, process: process, status: Operation::NOT_STARTED, manager: process.manager, dependencies: prepared_dependencies) end