Class: RespondToPb

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_respond_to_pb/respond_to_pb.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RespondToPb

Returns a new instance of RespondToPb.



6
7
8
# File 'lib/rails_respond_to_pb/respond_to_pb.rb', line 6

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rails_respond_to_pb/respond_to_pb.rb', line 10

def call(env)
  _, @resource, @action = env['PATH_INFO'].split('/')
  @resource = @resource.split('.').map(&:camelize).join('::')

  if env['CONTENT_TYPE'] == Twirp::Encoding::PROTO
    env['HTTP_ACCEPT'] = Twirp::Encoding::PROTO
    service.call(env)
  else
    @app.call(env)
  end
end