Class: Flexo::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/flexo/handler.rb

Overview

As seen in Flexo::Dispatcher. This is the class that’s spawned to handle a subscription to an event.

Each call to Flexo::Dispatcher.subscribe creates an instance of Flexo::Handler, which is called when the event fires.

Also, to unsubscribe, the original handle-object is required. So don’t throw it away.

Instance Method Summary collapse

Constructor Details

#initialize(numeric, &block) ⇒ Handler

This just stores some instance variables



14
15
16
17
18
# File 'lib/flexo/handler.rb', line 14

def initialize(numeric, &block)
  @manager = Flexo::Manager.instance
  @numeric = numeric
  @block   = block
end

Instance Method Details

#call(event) ⇒ Object

While this function does the actuall calling of the block. So when this function, aptly named ‘call’, is called, the block passed as block when creating this instance, is executed.



24
25
26
27
28
# File 'lib/flexo/handler.rb', line 24

def call(event)
  if !@numeric || event.class == Flexo::Events::ReplyEvent && @numeric == event.numeric
    @manager.thread { @block.call(event) }
  end
end