class Terminalwire::Client::Resource::Handler

Dispatches messages from the Client::Handler to the appropriate resource.

def add(resource)

def add(resource)
  # Detect if the resource is already registered and throw an error
  if @resources.key?(resource.name)
    raise "Resource #{resource.name} already registered"
  else
    @resources[resource.name] = resource
  end
end

def dispatch(**message)

def dispatch(**message)
  case message
  in { event:, action:, name:, command:, parameters: }
    resource = @resources.fetch(name)
    resource.command(command, **parameters)
  end
end

def each(&block)

def each(&block)
  @resources.values.each(&block)
end

def initialize

def initialize
  @resources = {}
  yield self if block_given?
end