Class: ActiveRemote::RPCAdapters::ProtobufAdapter

Inherits:
Object
  • Object
show all
Includes:
Serializers::Protobuf
Defined in:
lib/active_remote/rpc_adapters/protobuf_adapter.rb

Constant Summary

Constants included from Serializers::Protobuf

Serializers::Protobuf::FIELD_TYPE_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializers::Protobuf

#fields_from_attributes, type_name_for_field

Constructor Details

#initialize(service_class, endpoints) ⇒ ProtobufAdapter

Constructor!



16
17
18
19
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 16

def initialize(service_class, endpoints)
  @service_class = service_class
  @endpoints = endpoints
end

Instance Attribute Details

#endpointsObject

Returns the value of attribute endpoints.



9
10
11
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 9

def endpoints
  @endpoints
end

#service_classObject (readonly)

Returns the value of attribute service_class.



8
9
10
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 8

def service_class
  @service_class
end

Instance Method Details

#execute(endpoint, request_args) ⇒ Object

Invoke an RPC call to the service for the given rpc method.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 23

def execute(endpoint, request_args)
  rpc_method = endpoints.fetch(endpoint) { endpoint }
  request = build_request(rpc_method, request_args)
  response = nil

  client.send(rpc_method, request) do |c|
    # In the event of service failure, raise the error.
    c.on_failure do |error|
      protobuf_error = protobuf_error_class(error)
      raise protobuf_error, error.message
    end

    # In the event of service success, assign the response.
    c.on_success do |rpc_response|
      response = rpc_response
    end
  end

  response
end