Class: Itsi::Server::Config::Grpc

Inherits:
Middleware show all
Defined in:
lib/itsi/server/config/middleware/grpc.rb

Instance Method Summary collapse

Methods included from ConfigHelpers

included, load_and_register, #normalize_keys!

Constructor Details

#initialize(location, *handlers, reflection: true, nonblocking: false, &block) ⇒ Grpc

Returns a new instance of Grpc.



31
32
33
34
35
36
37
38
# File 'lib/itsi/server/config/middleware/grpc.rb', line 31

def initialize(location, *handlers, reflection: true, nonblocking: false, &block)
  super(location, {
    handlers: handlers,
    reflection: reflection,
    nonblocking: nonblocking,
    inner_block: block
  })
end

Instance Method Details

#build!Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/itsi/server/config/middleware/grpc.rb', line 40

def build!
  location.grpc_reflection(@params[:handlers]) if @params[:reflection]
  nonblocking = @params[:nonblocking]
  blk = @params[:inner_block]
  @params[:handlers].each do |handler|
    location.location(Regexp.new("#{Regexp.escape(handler.class.service_name)}/(?:#{handler.class.rpc_descs.keys.map(&:to_s).join("|")})")) do
      @middleware[:app] = { preloader: -> { Itsi::Server::GrpcInterface.for(handler) }, request_type: "grpc", nonblocking: nonblocking }
      instance_exec(&blk) if blk
    end
  end
end