class RailsWorkflow::EventManager

This manager controls events processing. Searches matching event operations for a given event and merges event context to matched event operations.

Public Class Methods

create_event(tag, context = {}) click to toggle source
# File lib/rails_workflow/event_manager.rb, line 8
def create_event(tag, context = {})
  new(tag, context).handle
end
new(tag, context = {}) click to toggle source
# File lib/rails_workflow/event_manager.rb, line 13
def initialize(tag, context = {})
  @tag = tag
  @context = context
end

Public Instance Methods

handle() click to toggle source
# File lib/rails_workflow/event_manager.rb, line 18
def handle
  event_operations.each do |event_operation|
    next if not_matches(event_operation)

    process_multiple_event(event_operation)
    event_operation.data.merge!(@context)
    event_operation.complete
  end
end

Private Instance Methods

config() click to toggle source
# File lib/rails_workflow/event_manager.rb, line 57
def config
  RailsWorkflow.config
end
event_operations() click to toggle source
# File lib/rails_workflow/event_manager.rb, line 44
def event_operations
  Operation.events.where(tag: @tag, status: Status::WAITING).all
end
not_matches(event_operation) click to toggle source
# File lib/rails_workflow/event_manager.rb, line 40
def not_matches(event_operation)
  event_operation.respond_to?(:match) && !event_operation.match(@context)
end
operation_builder() click to toggle source

TODO: refactor all operation_builder, and other configuration methods

# File lib/rails_workflow/event_manager.rb, line 49
def operation_builder
  config.operation_builder
end
operation_runner() click to toggle source
# File lib/rails_workflow/event_manager.rb, line 53
def operation_runner
  config.operation_runner
end
process_multiple_event(event_operation) click to toggle source
# File lib/rails_workflow/event_manager.rb, line 30
def process_multiple_event(event_operation)
  return unless event_operation.multiple?

  new_event_operation = operation_builder.new(
    event_operation.process, event_operation.template, [event_operation]
  ).create_operation

  new_event_operation.start
end