Class: Gruf::Controllers::Base
- Inherits:
-
Object
- Object
- Gruf::Controllers::Base
- Includes:
- Errors::Helpers
- Defined in:
- lib/gruf/controllers/base.rb
Overview
Base controller object for Gruf gRPC requests
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Class Method Summary collapse
-
.bind(service) ⇒ Object
Bind the controller to the given service and add it to the service registry.
Instance Method Summary collapse
-
#call(method_key, &block) ⇒ Object
Call a method on this controller.
-
#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Base
constructor
Initialize the controller within the given request context.
Methods included from Errors::Helpers
Constructor Details
#initialize(method_key:, service:, rpc_desc:, active_call:, message:) ⇒ Base
Initialize the controller within the given request context
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gruf/controllers/base.rb', line 41 def initialize(method_key:, service:, rpc_desc:, active_call:, message:) @request = Request.new( method_key: method_key, service: service, rpc_desc: rpc_desc, active_call: active_call, message: ) @error = Gruf::Error.new @interceptors = Gruf.interceptors.prepare(@request, @error) end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
30 31 32 |
# File 'lib/gruf/controllers/base.rb', line 30 def error @error end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
28 29 30 |
# File 'lib/gruf/controllers/base.rb', line 28 def request @request end |
Class Method Details
.bind(service) ⇒ Object
Bind the controller to the given service and add it to the service registry
58 59 60 61 |
# File 'lib/gruf/controllers/base.rb', line 58 def self.bind(service) Gruf.services << service.name.constantize ServiceBinder.new(service).bind!(self) end |
Instance Method Details
#call(method_key, &block) ⇒ Object
Call a method on this controller
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gruf/controllers/base.rb', line 68 def call(method_key, &block) Interceptors::Context.new(@interceptors).intercept! do send(method_key, &block) end rescue GRPC::BadStatus raise # passthrough rescue StandardError => e set_debug_info(e., e.backtrace) if Gruf.backtrace_on_error = Gruf. ? e. : Gruf. fail!(:internal, :unknown, ) end |