Class: Melomel::ObjectProxy
Instance Attribute Summary collapse
-
#bridge ⇒ Object
readonly
Returns the value of attribute bridge.
-
#proxy_id ⇒ Object
readonly
Returns the value of attribute proxy_id.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Array accessor.
-
#[]=(index, value) ⇒ Object
Array mutator.
-
#get_property(name) ⇒ Object
Retrieves the value of a property for the proxied object.
- #get_property!(name) ⇒ Object
-
#initialize(bridge, proxy_id) ⇒ ObjectProxy
constructor
A new instance of ObjectProxy.
-
#invoke_method(method_name, *args) ⇒ Object
(also: #invoke)
Invokes a method on the proxied object.
- #invoke_method!(method_name, *args) ⇒ Object
-
#method_missing(symbol, *args) ⇒ Object
Proxies all methods to the appropriate Flash objects.
-
#set_property(name, value) ⇒ Object
Sets the value of a property for the proxied object.
-
#set_property!(name, value) ⇒ Object
Sets the value of a property for the proxied object.
Constructor Details
#initialize(bridge, proxy_id) ⇒ ObjectProxy
Returns a new instance of ObjectProxy.
15 16 17 18 |
# File 'lib/melomel/object_proxy.rb', line 15 def initialize(bridge, proxy_id) @bridge = bridge @proxy_id = proxy_id end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args) ⇒ Object
Proxies all methods to the appropriate Flash objects.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/melomel/object_proxy.rb', line 52 def method_missing(symbol, *args) method_name = symbol.to_s last_char = method_name.to_s[-1,1] # Methods ending in "=" are aliased to set_property if last_char == '=' return set_property(method_name.chop, *args) # Methods with arguments are methods elsif args.length > 0 if last_char == '!' return invoke_method!(method_name.chop, *args) else return invoke_method(method_name, *args) end # Methods with no arguments are aliased to get_property else if last_char == '!' return get_property!(method_name.chop) else return get_property(method_name) end end end |
Instance Attribute Details
#bridge ⇒ Object (readonly)
Returns the value of attribute bridge.
13 14 15 |
# File 'lib/melomel/object_proxy.rb', line 13 def bridge @bridge end |
#proxy_id ⇒ Object (readonly)
Returns the value of attribute proxy_id.
13 14 15 |
# File 'lib/melomel/object_proxy.rb', line 13 def proxy_id @proxy_id end |
Instance Method Details
#[](index) ⇒ Object
Array accessor.
77 78 79 80 81 82 83 |
# File 'lib/melomel/object_proxy.rb', line 77 def [](index) if index.is_a?(Fixnum) get_property("[#{index}]") else get_property(index.to_s) end end |
#[]=(index, value) ⇒ Object
Array mutator.
86 87 88 89 90 91 92 |
# File 'lib/melomel/object_proxy.rb', line 86 def []=(index, value) if index.is_a?(Fixnum) set_property("[#{index}]", value) else set_property(index.to_s, value) end end |
#get_property(name) ⇒ Object
Retrieves the value of a property for the proxied object.
21 22 23 |
# File 'lib/melomel/object_proxy.rb', line 21 def get_property(name) @bridge.get_property(@proxy_id, name) end |
#get_property!(name) ⇒ Object
25 26 27 |
# File 'lib/melomel/object_proxy.rb', line 25 def get_property!(name) @bridge.get_property!(@proxy_id, name) end |
#invoke_method(method_name, *args) ⇒ Object Also known as: invoke
Invokes a method on the proxied object. Arguments passed into the method are passed through to the invoked method
41 42 43 |
# File 'lib/melomel/object_proxy.rb', line 41 def invoke_method(method_name, *args) @bridge.invoke_method(@proxy_id, method_name, *args) end |
#invoke_method!(method_name, *args) ⇒ Object
45 46 47 |
# File 'lib/melomel/object_proxy.rb', line 45 def invoke_method!(method_name, *args) @bridge.invoke_method!(@proxy_id, method_name, *args) end |
#set_property(name, value) ⇒ Object
Sets the value of a property for the proxied object.
30 31 32 |
# File 'lib/melomel/object_proxy.rb', line 30 def set_property(name, value) @bridge.set_property(@proxy_id, name, value) end |
#set_property!(name, value) ⇒ Object
Sets the value of a property for the proxied object.
35 36 37 |
# File 'lib/melomel/object_proxy.rb', line 35 def set_property!(name, value) @bridge.set_property!(@proxy_id, name, value) end |