class Controll::Flow::Master::Executor

Constants

Flow
NoEventsDefinedError
NoMappingFoundError

Attributes

action_handlers[R]
event[R]

Public Class Methods

new(initiator, options) click to toggle source
Calls superclass method Controll::Executor::Base::new
# File lib/controll/flow/master/executor.rb, line 11
def initialize initiator, options
  raise ArgumentError, "Must take an options arg" unless options.kind_of?(Hash)
  raise ArgumentError, "Must take an :event option" unless options[:event]
  raise ArgumentError, "Must take an :action_handlers option" unless options[:action_handlers]
  super
  @event = options[:event]
  @action_handlers = options[:action_handlers]
end

Public Instance Methods

errors() click to toggle source
# File lib/controll/flow/master/executor.rb, line 35
def errors
  @errors ||= []
end
execute() click to toggle source
# File lib/controll/flow/master/executor.rb, line 20
def execute        
  action_handlers.each do |action_handler|
    begin          
      action_handler_clazz = handler_class(action_handler)
      next unless action_handler_clazz
      return action_handler_clazz.action(controller, event)
    rescue NoEventsDefinedError => e
      errors << e
    rescue NoMappingFoundError => e
      errors << e
    end
  end
  fallback
end

Protected Instance Methods

fallback() click to toggle source
# File lib/controll/flow/master/executor.rb, line 41
def fallback
  fallback_class.new controller, event
end
fallback_class() click to toggle source
# File lib/controll/flow/master/executor.rb, line 45
def fallback_class
  Flow::Action::Fallback
end
handler_class(action_handler) click to toggle source
# File lib/controll/flow/master/executor.rb, line 49
def handler_class action_handler
  clazz = "#{initiator.class}::#{action_handler.to_s.camelize}"
  clazz.constantize
rescue NameError
  nil
end