Class: Gruf::Client
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Gruf::Client
- Includes:
- Loggable
- Defined in:
- lib/gruf/client.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#base_klass ⇒ Object
readonly
Returns the value of attribute base_klass.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#service_klass ⇒ Object
readonly
Returns the value of attribute service_klass.
Instance Method Summary collapse
-
#call(request_method, params = {}, metadata = {}) ⇒ Object
Call the client’s method with given params.
-
#initialize(service:, options: {}) ⇒ Client
constructor
A new instance of Client.
Methods included from Loggable
Constructor Details
#initialize(service:, options: {}) ⇒ Client
Returns a new instance of Client.
37 38 39 40 41 42 43 44 45 |
# File 'lib/gruf/client.rb', line 37 def initialize(service:, options: {}) @base_klass = service @service_klass = "#{base_klass}::Service".constantize @opts = || {} @opts[:password] = .fetch(:password, '').to_s @opts[:hostname] = .fetch(:hostname, Gruf.default_client_host) client = "#{service}::Stub".constantize.new(@opts[:hostname], build_ssl_credentials) super(client) end |
Instance Attribute Details
#base_klass ⇒ Object (readonly)
Returns the value of attribute base_klass.
29 30 31 |
# File 'lib/gruf/client.rb', line 29 def base_klass @base_klass end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
29 30 31 |
# File 'lib/gruf/client.rb', line 29 def opts @opts end |
#service_klass ⇒ Object (readonly)
Returns the value of attribute service_klass.
29 30 31 |
# File 'lib/gruf/client.rb', line 29 def service_klass @service_klass end |
Instance Method Details
#call(request_method, params = {}, metadata = {}) ⇒ Object
Call the client’s method with given params
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gruf/client.rb', line 50 def call(request_method, params = {}, = {}) req = request_object(request_method, params) md = () call_sig = call_signature(request_method) raise NotImplementedError, "The method #{request_method} has not been implemented in this service." unless call_sig execute(call_sig, req, md) rescue GRPC::BadStatus => e emk = Gruf..to_s raise Gruf::Client::Error, error_deserializer_class.new(e.[emk]).deserialize if e.respond_to?(:metadata) && e..key?(emk) raise # passthrough end |