class ScoutApm::Remote::Router

Attributes

logger[R]
routes[R]

Public Class Methods

new(recorder, logger) click to toggle source

If/When we add different types, this signature should change to a hash of {type => Object}, rather than building it in the initializer here.

Keys of routes should be strings

# File lib/scout_apm/remote/router.rb, line 11
def initialize(recorder, logger)
  @routes = {
    'record' => recorder
  }

  @logger = logger
end

Public Instance Methods

handle(msg) click to toggle source

A message is a 2 element array [:type, :command, [args]]. For this first creation, this should be ['record', 'record', [TrackedRequest]] (the args arg should always be an array, even w/ only 1 item)

Where

type: ['recorder']
command: any function supported on that type of object
args: any array of arguments

Raises on unknown message

Returns whatever the recipient object returns

# File lib/scout_apm/remote/router.rb, line 30
def handle(msg)
  message = Remote::Message.decode(msg)
  assert_type(message)
  call_route(message)
end

Private Instance Methods

assert_type(message) click to toggle source
# File lib/scout_apm/remote/router.rb, line 38
def assert_type(message)
  if ! routes.keys.include?(message.type.to_s)
    raise "Unknown type: #{message.type.to_s}"
  end
end
call_route(message) click to toggle source
# File lib/scout_apm/remote/router.rb, line 44
def call_route(message)
  routes[message.type].send(message.command, *message.args)
end