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
Class Attribute Summary collapse
-
.bound_service ⇒ Object
readonly
Returns the value of attribute bound_service.
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.
-
#process_action(method_key, &block) ⇒ Object
Call a method on this controller.
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
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gruf/controllers/base.rb', line 51 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 |
Class Attribute Details
.bound_service ⇒ Object (readonly)
Returns the value of attribute bound_service.
39 40 41 |
# File 'lib/gruf/controllers/base.rb', line 39 def bound_service @bound_service end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
34 35 36 |
# File 'lib/gruf/controllers/base.rb', line 34 def error @error end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
31 32 33 |
# File 'lib/gruf/controllers/base.rb', line 31 def request @request end |
Class Method Details
.bind(service) ⇒ Object
Bind the controller to the given service and add it to the service registry
68 69 70 71 72 73 74 75 |
# File 'lib/gruf/controllers/base.rb', line 68 def self.bind(service) service_class = service.name.constantize Gruf.services << service_class # rubocop:disable ThreadSafety/InstanceVariableInClassMethod @bound_service = service_class # rubocop:enable ThreadSafety/InstanceVariableInClassMethod ServiceBinder.new(service_class).bind!(self) end |
Instance Method Details
#call(method_key, &block) ⇒ Object
Call a method on this controller
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/gruf/controllers/base.rb', line 94 def call(method_key, &block) Interceptors::Context.new(@interceptors).intercept! do process_action(method_key, &block) end rescue GRPC::BadStatus raise # passthrough, to be caught by Gruf::Interceptors::Timer rescue GRPC::Core::CallError, StandardError => e # CallError is not a StandardError set_debug_info(e., e.backtrace) if Gruf.backtrace_on_error = Gruf. ? e. : Gruf. fail!(:internal, :unknown, ) end |
#process_action(method_key, &block) ⇒ Object
Call a method on this controller. Override this in a subclass to modify the behavior around processing a method
84 85 86 |
# File 'lib/gruf/controllers/base.rb', line 84 def process_action(method_key, &block) send(method_key, &block) end |