Module: Gruf::Service
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/gruf/service.rb
Overview
Module for gRPC endpoints
Instance Method Summary collapse
-
#after_call(success, response, call_signature, req, call) ⇒ Object
Happens after a call.
-
#around_call(call_signature, req, call, &block) ⇒ Object
Happens around a call.
-
#authenticate(_method, req, call) ⇒ Object
Authenticate the endpoint caller.
-
#before_call(call_signature, req, call) ⇒ Object
Happens before a call.
-
#fail!(_req, call, error_code, app_code = nil, message = '', metadata = {}) ⇒ RPC::Error
Will issue a GRPC BadStatus exception, with a code based on the code passed.
-
#outer_around_call(call_signature, req, call, &block) ⇒ Object
Happens around the entire call chain - before, around, the call itself, and after hooks.
-
#run_around_hook(hooks, call_signature, req, call, &_) ⇒ Object
Run all around hooks recursively, starting with the last loaded.
-
#run_outer_around_hook(hooks, call_signature, req, call, &_) ⇒ Object
Run all outer around hooks recursively, starting with the last loaded.
Instance Method Details
#after_call(success, response, call_signature, req, call) ⇒ Object
Happens after a call
164 165 166 167 168 |
# File 'lib/gruf/service.rb', line 164 def after_call(success, response, call_signature, req, call) Gruf::Hooks::Registry.each do |_name, h| h.new(self, Gruf.).after(success, response, call_signature, req, call) if h.instance_methods.include?(:after) end end |
#around_call(call_signature, req, call, &block) ⇒ Object
Happens around a call.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gruf/service.rb', line 85 def around_call(call_signature, req, call, &block) around_hooks = [] Gruf::Hooks::Registry.each do |_name, h| around_hooks << h.new(self, Gruf.) if h.instance_methods.include?(:around) end if around_hooks.any? run_around_hook(around_hooks, call_signature, req, call, &block) else yield end end |
#authenticate(_method, req, call) ⇒ Object
Authenticate the endpoint caller.
177 178 179 |
# File 'lib/gruf/service.rb', line 177 def authenticate(_method, req, call) fail!(req, call, :unauthenticated) unless Authentication.verify(call) end |
#before_call(call_signature, req, call) ⇒ Object
Happens before a call.
71 72 73 74 75 76 |
# File 'lib/gruf/service.rb', line 71 def before_call(call_signature, req, call) authenticate(call_signature, req, call) Gruf::Hooks::Registry.each do |_name, h| h.new(self, Gruf.).before(call_signature, req, call) if h.instance_methods.include?(:before) end end |
#fail!(_req, call, error_code, app_code = nil, message = '', metadata = {}) ⇒ RPC::Error
Will issue a GRPC BadStatus exception, with a code based on the code passed.
192 193 194 195 196 197 198 |
# File 'lib/gruf/service.rb', line 192 def fail!(_req, call, error_code, app_code = nil, = '', = {}) error.code = error_code.to_sym error.app_code = app_code ? app_code.to_sym : error.code error. = .to_s error. = error.fail!(call) end |
#outer_around_call(call_signature, req, call, &block) ⇒ Object
Happens around the entire call chain - before, around, the call itself, and after hooks.
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/gruf/service.rb', line 123 def outer_around_call(call_signature, req, call, &block) outer_around_hooks = [] Gruf::Hooks::Registry.each do |_name, h| outer_around_hooks << h.new(self, Gruf.) if h.instance_methods.include?(:outer_around) end if outer_around_hooks.any? run_outer_around_hook(outer_around_hooks, call_signature, req, call, &block) else yield end end |
#run_around_hook(hooks, call_signature, req, call, &_) ⇒ Object
Run all around hooks recursively, starting with the last loaded
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/gruf/service.rb', line 105 def run_around_hook(hooks, call_signature, req, call, &_) h = hooks.pop h.around(call_signature, req, call) do if hooks.any? run_around_hook(hooks, call_signature, req, call) { yield } else yield end end end |
#run_outer_around_hook(hooks, call_signature, req, call, &_) ⇒ Object
Run all outer around hooks recursively, starting with the last loaded
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/gruf/service.rb', line 143 def run_outer_around_hook(hooks, call_signature, req, call, &_) h = hooks.pop h.outer_around(call_signature, req, call) do if hooks.any? run_outer_around_hook(hooks, call_signature, req, call) { yield } else yield end end end |