Class: AgentClientProtocol::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_client_protocol/router.rb

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



5
6
7
8
9
10
# File 'lib/agent_client_protocol/router.rb', line 5

def initialize
  @request_handlers = {}
  @notification_handlers = {}
  @ext_method_handler = nil
  @ext_notification_handler = nil
end

Instance Method Details

#call(method, params, is_notification) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/agent_client_protocol/router.rb', line 36

def call(method, params, is_notification)
  if is_notification
    dispatch_notification(method, params)
  else
    dispatch_request(method, params)
  end
end

#on_ext_method(&handler) ⇒ Object



28
29
30
# File 'lib/agent_client_protocol/router.rb', line 28

def on_ext_method(&handler)
  @ext_method_handler = handler
end

#on_ext_notification(&handler) ⇒ Object



32
33
34
# File 'lib/agent_client_protocol/router.rb', line 32

def on_ext_notification(&handler)
  @ext_notification_handler = handler
end

#on_notification(method, request_class: nil, &handler) ⇒ Object



21
22
23
24
25
26
# File 'lib/agent_client_protocol/router.rb', line 21

def on_notification(method, request_class: nil, &handler)
  @notification_handlers[method] = {
    handler: handler,
    request_class: request_class
  }
end

#on_request(method, request_class: nil, response_class: nil, optional: false, &handler) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/agent_client_protocol/router.rb', line 12

def on_request(method, request_class: nil, response_class: nil, optional: false, &handler)
  @request_handlers[method] = {
    handler: handler,
    request_class: request_class,
    response_class: response_class,
    optional: optional
  }
end