Class: Controll::Flow::Master::Executor

Inherits:
Executor::Base show all
Defined in:
lib/controll/flow/master/executor.rb

Constant Summary collapse

Flow =
Controll::Flow
NoEventsDefinedError =
Flow::NoEventsDefinedError
NoMappingFoundError =
Flow::NoMappingFoundError

Instance Attribute Summary collapse

Attributes inherited from Executor::Base

#controller, #options

Instance Method Summary collapse

Constructor Details

#initialize(initiator, options) ⇒ Executor

Returns a new instance of Executor.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#action_handlersObject (readonly)

Returns the value of attribute action_handlers.



9
10
11
# File 'lib/controll/flow/master/executor.rb', line 9

def action_handlers
  @action_handlers
end

#eventObject (readonly)

Returns the value of attribute event.



9
10
11
# File 'lib/controll/flow/master/executor.rb', line 9

def event
  @event
end

Instance Method Details

#errorsObject



35
36
37
# File 'lib/controll/flow/master/executor.rb', line 35

def errors
  @errors ||= []
end

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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