class ScoutApm::Remote::Router
Attributes
Public Class Methods
Source
# File lib/scout_apm/remote/router.rb, line 11 def initialize(recorder, logger) @routes = { 'record' => recorder } @logger = logger end
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
Public Instance Methods
Source
# File lib/scout_apm/remote/router.rb, line 30 def handle(msg) message = Remote::Message.decode(msg) assert_type(message) call_route(message) end
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
Private Instance Methods
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
Source
# File lib/scout_apm/remote/router.rb, line 44 def call_route(message) routes[message.type].send(message.command, *message.args) end