Class: Omega::Server::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/omega/server/callback.rb

Overview

Base Omega Callback, through which a specified handler may be invoked on certain conditions.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}, &block) ⇒ Callback

Omega::Server::Callback initializer

Options Hash (args):

  • :only_if,'only_if' (Callable)

    procedure to use to check handling conditions

  • :handler,'handler' (Callable)

    handler to invoke on the event

  • &block (Callable)

    block parameter used as handler if specified

  • :endpoint_id,'endpoint_id' (String)

    endpoint_id registering this callback

  • :rjr_event, (String)

    'rjr_event' event which callback handler should invoke

  • :event_type, (String)

    'event_type' which this callback represents


37
38
39
40
41
42
43
# File 'lib/omega/server/callback.rb', line 37

def initialize(args = {}, &block)
  attr_from_args args, :only_if      => proc { true },
                       :handler      => block,
                       :endpoint_id  => nil,
                       :event_type   => nil,
                       :rjr_event    => nil
end

Instance Attribute Details

#endpoint_idObject

RJR Node Endpoint which this callback is registered for


20
21
22
# File 'lib/omega/server/callback.rb', line 20

def endpoint_id
  @endpoint_id
end

#event_typeObject

The event which this callback should be registered for


23
24
25
# File 'lib/omega/server/callback.rb', line 23

def event_type
  @event_type
end

#handlerObject

Callable object to be invoked upon callback event TODO make handler an array of handlers


17
18
19
# File 'lib/omega/server/callback.rb', line 17

def handler
  @handler
end

#only_ifObject

Callable to determine if callback handler should be invoked


13
14
15
# File 'lib/omega/server/callback.rb', line 13

def only_if
  @only_if
end

#rjr_eventObject

JSON-RPC method on client which is invoked by this callback


26
27
28
# File 'lib/omega/server/callback.rb', line 26

def rjr_event
  @rjr_event
end

Instance Method Details

#invoke(*args) ⇒ Object

Invoke the registered handler w/ the specified args


53
54
55
# File 'lib/omega/server/callback.rb', line 53

def invoke(*args)
  handler.call *args
end

#should_invoke?(*args) ⇒ Boolean

Return bool indicating if handler should be run


46
47
48
# File 'lib/omega/server/callback.rb', line 46

def should_invoke?(*args)
  only_if.call *args
end