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::TYPECASTER_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializers::Protobuf

#fields_from_attributes

Constructor Details

#initialize(service_class) ⇒ ProtobufAdapter

Constructor!



13
14
15
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 13

def initialize(service_class)
  @service_class = service_class
end

Instance Attribute Details

#last_requestObject (readonly)

Returns the value of attribute last_request.



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

def last_request
  @last_request
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



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

def last_response
  @last_response
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(rpc_method, request_args) ⇒ Object

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_remote/rpc_adapters/protobuf_adapter.rb', line 19

def execute(rpc_method, request_args)
  @last_request = request(rpc_method, request_args)

  service_class.client.__send__(rpc_method, @last_request) do |c|
    # In the event of service failure, raise the error.
    c.on_failure do |error|
      raise ActiveRemoteError, error.message
    end

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

  @last_response
end