Class: Edrive::ProcessorDispatcher

Inherits:
Dispatcher show all
Defined in:
lib/edrive/processor_dispatcher.rb

Constant Summary collapse

DEFINED_EVENT =

Returns defined event symbols.

Returns:

  • (Array)

    defined event symbols

i[before_process after_process].freeze
DEFAULT_PROCESSOR_PROCESS =

Returns default processor process symbol.

Returns:

  • (Symbol)

    default processor process symbol

:process

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Dispatcher

#clear!, #clear_all!, #dispatch, #dispatch_with_data, #handlers

Constructor Details

#initialize(processor, processor_process = DEFAULT_PROCESSOR_PROCESS) ⇒ ProcessorDispatcher

Initialize

Parameters:

  • processor (Processor)

    processor object

  • processor_process (Symbol) (defaults to: DEFAULT_PROCESSOR_PROCESS)

    processor main method



22
23
24
25
26
# File 'lib/edrive/processor_dispatcher.rb', line 22

def initialize(processor, processor_process = DEFAULT_PROCESSOR_PROCESS)
  super()
  @processor = processor
  @processor_process = processor_process
end

Instance Attribute Details

#processorObject

Returns the value of attribute processor.



11
12
13
# File 'lib/edrive/processor_dispatcher.rb', line 11

def processor
  @processor
end

#processor_processObject

Returns the value of attribute processor_process.



11
12
13
# File 'lib/edrive/processor_dispatcher.rb', line 11

def processor_process
  @processor_process
end

Instance Method Details

#dispatch_all(use_result = true) ⇒ Mixed

Dispatch all events

Parameters:

  • use_result (Boolean) (defaults to: true)

    use processor process result in after_process event

Returns:

  • (Mixed)

    last subscriber return value



42
43
44
45
46
47
48
49
50
# File 'lib/edrive/processor_dispatcher.rb', line 42

def dispatch_all(use_result = true)
  dispatch(DEFINED_EVENT[0])
  if use_result
    result = dispatch_processor_process
    return dispatch_with_data(DEFINED_EVENT[1], result)
  end
  dispatch_processor_process
  dispatch(DEFINED_EVENT[1])
end

#dispatch_processor_process(*args) ⇒ Mixed

Dispach processor process

Parameters:

  • args (Mixed)

Returns:

  • (Mixed)

    processor process return value



55
56
57
# File 'lib/edrive/processor_dispatcher.rb', line 55

def dispatch_processor_process(*args)
  processor.send(processor_process, *args)
end

#subscribe(event, handler = nil, &block) ⇒ Array

subscribe handler (proc, lambda, block)

Parameters:

  • event (Symbol)

    event name symbol

  • handler (Proc) (defaults to: nil)

    handler (lambda, proc)

  • block (Block)

    handler (block)

Returns:

  • (Array)

    registered handler list

Raises:

  • ArgumentError



34
35
36
37
# File 'lib/edrive/processor_dispatcher.rb', line 34

def subscribe(event, handler = nil, &block)
  undefined_event_protect(event)
  super
end