Class: GRPCWeb::RackApp

Inherits:
Rack::Builder
  • Object
show all
Defined in:
lib/grpc_web/server/rack_app.rb

Overview

Can be given a service class, an instance of a service class, or a service interface class with a block to lazily initialize the service.

Example 1:

app.handle(TestHelloService)

Example 2:

app.handle(TestHelloService.new)

Example 3:

app.handle(HelloService::Service) do
  require 'test_hello_service'
  TestHelloService.new
end

TODO: in-mem cache the result of lazy initialization

Defined Under Namespace

Classes: RouteHandler

Instance Method Summary collapse

Instance Method Details

#handle(service_or_class, &lazy_init_block) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/grpc_web/server/rack_app.rb', line 24

def handle(service_or_class, &lazy_init_block)
  service_class = service_or_class.is_a?(Class) ? service_or_class : service_or_class.class
  GRPCWeb::ServiceClassValidator.validate(service_class)
  service_config = lazy_init_block || service_or_class

  service_class.rpc_descs.keys.each do |service_method|
    add_service_method_to_app(service_class.service_name, service_config, service_method)
  end
end