Class: Async::Bus::Protocol::Proxy

Inherits:
BasicObject
Defined in:
lib/async/bus/protocol/proxy.rb

Overview

A proxy object that forwards method calls to a remote object.

We must be extremely careful not to invoke any methods on the proxy object that would recursively call the proxy object.

Instance Method Summary collapse

Constructor Details

#initialize(connection, name) ⇒ Proxy

Create a new proxy object.



17
18
19
20
# File 'lib/async/bus/protocol/proxy.rb', line 17

def initialize(connection, name)
	@connection = connection
	@name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*arguments, **options, &block) ⇒ Object

Forward method calls to the remote object.



59
60
61
# File 'lib/async/bus/protocol/proxy.rb', line 59

def method_missing(*arguments, **options, &block)
	@connection.invoke(@name, arguments, options, &block)
end

Instance Method Details

#!Object

Logical negation operator.



36
37
38
# File 'lib/async/bus/protocol/proxy.rb', line 36

def !
	@connection.invoke(@name, [:!])
end

#!=(object) ⇒ Object

Inequality operator.



50
51
52
# File 'lib/async/bus/protocol/proxy.rb', line 50

def != object
	@connection.invoke(@name, [:!=, object])
end

#==(object) ⇒ Object

Equality operator.



43
44
45
# File 'lib/async/bus/protocol/proxy.rb', line 43

def == object
	@connection.invoke(@name, [:==, object])
end

#__connection__Object

Get the connection to the remote object.



24
25
26
# File 'lib/async/bus/protocol/proxy.rb', line 24

def __connection__
	@connection
end

#__name__Object

Get the name of the remote object.



30
31
32
# File 'lib/async/bus/protocol/proxy.rb', line 30

def __name__
	@name
end

#inspectObject

Return a string representation of the proxy.



73
74
75
# File 'lib/async/bus/protocol/proxy.rb', line 73

def inspect
	"#<proxy #{@name}>"
end

#respond_to?(name, include_all = false) ⇒ Boolean

Check if the remote object responds to a method.

Returns:

  • (Boolean)


67
68
69
# File 'lib/async/bus/protocol/proxy.rb', line 67

def respond_to?(name, include_all = false)
	@connection.invoke(@name, [:respond_to?, name, include_all])
end