Class: Twirbet::Service
- Inherits:
-
Object
- Object
- Twirbet::Service
- Extended by:
- T::Sig
- Includes:
- DSL
- Defined in:
- lib/twirbet/service.rb
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(handler) ⇒ Service
constructor
A new instance of Service.
Methods included from DSL
#full_name, #package_name, #rpc, #service_name
Constructor Details
#initialize(handler) ⇒ Service
Returns a new instance of Service.
17 18 19 |
# File 'lib/twirbet/service.rb', line 17 def initialize(handler) @handler = handler end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
15 16 17 |
# File 'lib/twirbet/service.rb', line 15 def handler @handler end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/twirbet/service.rb', line 22 def call(env) request = Rack::Request.new(env) validate_request(request) method = request.env["twirp.method"] response = invoke_method(method, request) rack_response = Rack::Response.new(response, 200, "Content-Type" => request.content_type) rack_response.finish rescue => e Error.from_exception(e).to_rack_response.finish end |