Class: PipeRpc::Client
- Inherits:
-
BasicInterface
- Object
- BasicInterface
- PipeRpc::Client
- Defined in:
- lib/pipe_rpc/client.rb
Defined Under Namespace
Classes: Request
Constant Summary collapse
- TRANSPORT_PREFIX =
"__rpc_client__"
Instance Attribute Summary collapse
-
#__rpc_server_class_name__ ⇒ Object
readonly
Returns the value of attribute rpc_server_class_name.
-
#__rpc_server_id__ ⇒ Object
readonly
Returns the value of attribute rpc_server_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(server_id = :default, hub) ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, *args) ⇒ Object
- #respond_to?(*args) ⇒ Boolean
- #to_rpc_transport(gateway) ⇒ Object
Methods inherited from BasicInterface
add_instance_eval, const_missing, instance_eval_for, remove_instance_eval
Constructor Details
#initialize(server_id = :default, hub) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 |
# File 'lib/pipe_rpc/client.rb', line 7 def initialize(server_id = :default, hub) Kernel.raise ClientInitializationError.new("server id #{server_id.inspect} no symbol") unless server_id.is_a? Symbol @__rpc_server_id__ = server_id @__rpc_server_class_name__ = server_id.to_s.split('#').first @hub = hub end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
20 21 22 23 |
# File 'lib/pipe_rpc/client.rb', line 20 def method_missing(method, *args) request = Client::Request.new(@hub, server: @__rpc_server_id__, method: method, arguments: args) @hub.requests.evaluate(request) end |
Instance Attribute Details
#__rpc_server_class_name__ ⇒ Object (readonly)
Returns the value of attribute rpc_server_class_name.
14 15 16 |
# File 'lib/pipe_rpc/client.rb', line 14 def __rpc_server_class_name__ @__rpc_server_class_name__ end |
#__rpc_server_id__ ⇒ Object (readonly)
Returns the value of attribute rpc_server_id.
14 15 16 |
# File 'lib/pipe_rpc/client.rb', line 14 def __rpc_server_id__ @__rpc_server_id__ end |
Class Method Details
.from_rpc_transport(gateway, transport) ⇒ Object
31 32 33 34 |
# File 'lib/pipe_rpc/client.rb', line 31 def from_rpc_transport(gateway, transport) client = gateway.clients[transport.sub(Server::TRANSPORT_PREFIX, '').to_sym] ClientWrapper.from_rpc_transport(gateway, client) end |
Instance Method Details
#respond_to?(*args) ⇒ Boolean
16 17 18 |
# File 'lib/pipe_rpc/client.rb', line 16 def respond_to?(*args) super or method_missing(:respond_to?, *args) end |
#to_rpc_transport(gateway) ⇒ Object
25 26 27 |
# File 'lib/pipe_rpc/client.rb', line 25 def to_rpc_transport(gateway) "#{TRANSPORT_PREFIX}#{@__rpc_server_id__}" end |