Class: ProxyNobject
- Inherits:
-
Object
- Object
- ProxyNobject
- Defined in:
- lib/proxy_nobject.rb
Overview
this is the class that accepts instantiated objects in the main program, and then pushes them to a remote server
Defined Under Namespace
Classes: InvalidMethod, UnknownReturnDataType
Instance Method Summary collapse
-
#!~(other) ⇒ Object
method overridden from Object class.
- #<=>(other) ⇒ Object
- #===(other) ⇒ Object
-
#initialize(host, port, obj) ⇒ ProxyNobject
constructor
host: the hostname of the server to push obj to port: the port number of the server to push obj to obj: the obj to store over the network.
- #inspect ⇒ Object
- #is_a?(klass) ⇒ Boolean
- #method_missing(method, *args, **kwargs, &block) ⇒ Object
- #object_id ⇒ Object
Constructor Details
#initialize(host, port, obj) ⇒ ProxyNobject
host: the hostname of the server to push obj to port: the port number of the server to push obj to obj: the obj to store over the network
ex:
# this will create a new ProxyNobject, then put it to the specified server
ProxyNobject.new('localhost', 1234, <object>)
13 14 15 16 17 18 19 |
# File 'lib/proxy_nobject.rb', line 13 def initialize(host, port, obj) @socket = TCPSocket.new(host, port) obj_bytes = Marshal.dump(obj) @socket.send([obj_bytes.length].pack('Q>'), 0) @socket.send(obj_bytes, 0) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/proxy_nobject.rb', line 21 def method_missing(method, *args, **kwargs, &block) msg = { method: method, args: args } msg_bytes = Marshal.dump(msg) @socket.send([msg_bytes.length].pack('Q>'), 0) @socket.send(msg_bytes, 0) return_size = @socket.recv(8).unpack('Q>').first return_data = Marshal.load(@socket.recv(return_size)) case return_data.first when :ok then return_data.last when :raise then raise return_data.last else raise ProxyNobject::UnknownReturnDataType.new("unknown data type '#{return_data.first}' within ProxyNobject (ProxyNobject::UnknownReturnDataType)") end end |
Instance Method Details
#!~(other) ⇒ Object
method overridden from Object class
42 |
# File 'lib/proxy_nobject.rb', line 42 def !~(other); method_missing(:is_a?, other); end |
#<=>(other) ⇒ Object
43 |
# File 'lib/proxy_nobject.rb', line 43 def <=>(other); method_missing(:<=>, other); end |
#===(other) ⇒ Object
44 |
# File 'lib/proxy_nobject.rb', line 44 def ===(other); method_missing(:<=>, other); end |
#inspect ⇒ Object
46 |
# File 'lib/proxy_nobject.rb', line 46 def inspect; method_missing(:inspect); end |
#is_a?(klass) ⇒ Boolean
45 |
# File 'lib/proxy_nobject.rb', line 45 def is_a?(klass); method_missing(:is_a?, klass); end |
#object_id ⇒ Object
47 |
# File 'lib/proxy_nobject.rb', line 47 def object_id; method_missing(:object_id); end |