Module: ActiveRemote::RPC::ClassMethods
- Defined in:
- lib/active_remote/rpc.rb
Instance Method Summary collapse
-
#build_from_rpc(new_attributes) ⇒ Object
Builds an attribute hash that be assigned directly to an object from an rpc response.
-
#remote_call(rpc_method, request_args) ⇒ Object
Execute an RPC call to the remote service and return the raw response.
- #rpc ⇒ Object
- #rpc_adapter ⇒ Object
Instance Method Details
#build_from_rpc(new_attributes) ⇒ Object
Builds an attribute hash that be assigned directly to an object from an rpc response
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_remote/rpc.rb', line 15 def build_from_rpc(new_attributes) new_attributes = new_attributes.stringify_keys constructed_attributes = {} attributes.each do |name, definition| if new_attributes[name].nil? constructed_attributes[name] = nil elsif definition[:typecaster] constructed_attributes[name] = definition[:typecaster].call(new_attributes[name]) else constructed_attributes[name] = new_attributes[name] end end constructed_attributes end |
#remote_call(rpc_method, request_args) ⇒ Object
Execute an RPC call to the remote service and return the raw response.
32 33 34 |
# File 'lib/active_remote/rpc.rb', line 32 def remote_call(rpc_method, request_args) rpc.execute(rpc_method, request_args) end |
#rpc ⇒ Object
36 37 38 |
# File 'lib/active_remote/rpc.rb', line 36 def rpc rpc_adapter.new(service_class, endpoints) end |
#rpc_adapter ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_remote/rpc.rb', line 40 def rpc_adapter # TODO: Make this pluggable # # raise(AdapterNotSpecified, "configuration does not specify adapter") unless adapter.present? # # path_to_adapter = "active_remote/rpc_adapters/#{adapter}_adapter" # # begin # require path_to_adapter # rescue Gem::LoadError => e # raise Gem::LoadError, "Specified '#{adapter]}' for RPC adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by ActiveRemote)." # rescue LoadError => e # raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter is valid. If you use an adapter other than 'protobuf' add the necessary adapter gem to the Gemfile.", e.backtrace # end # # path_to_adapter.classify.constantize ::ActiveRemote::RPCAdapters::ProtobufAdapter end |