Class: TagListProxy
- Inherits:
-
Object
- Object
- TagListProxy
- Defined in:
- lib/scoped_tags/tag_list_proxy.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#===(other) ⇒ Object
Forwards
===
explicitly to the target because the instance method removal above doesn’t catch it. -
#initialize(owner, context) ⇒ TagListProxy
constructor
A new instance of TagListProxy.
-
#inspect ⇒ Object
Forwards the call to the target.
-
#proxy_context ⇒ Object
Returns the context of the proxy, same as
context
. -
#proxy_owner ⇒ Object
Returns the owner of the proxy.
- #proxy_respond_to? ⇒ Object
-
#proxy_target ⇒ Object
Returns the target of the proxy, same as
target
. -
#reload ⇒ Object
Reloads the target and returns
self
on success. -
#respond_to?(*args) ⇒ Boolean
Does the proxy or its target respond to
symbol
?. - #send(method, *args) ⇒ Object
-
#target ⇒ Object
Returns the target of this proxy, same as
proxy_target
. -
#target=(target) ⇒ Object
Sets the target of this proxy to
\target
, and the loaded flag totrue
.
Constructor Details
#initialize(owner, context) ⇒ TagListProxy
Returns a new instance of TagListProxy.
8 9 10 11 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 8 def initialize(owner, context) @owner, @context = owner, context @target = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
Forwards any missing method call to the target.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 75 def method_missing(method, *args) if reload unless @target.respond_to?(method) = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" raise NoMethodError, end if block_given? @target.send(method, *args) { |*block_args| yield(*block_args) } else @target.send(method, *args) end end end |
Instance Method Details
#===(other) ⇒ Object
Forwards ===
explicitly to the target because the instance method removal above doesn’t catch it. Loads the target if needed.
35 36 37 38 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 35 def ===(other) reload other === @target end |
#inspect ⇒ Object
Forwards the call to the target. Loads the target if needed.
58 59 60 61 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 58 def inspect reload @target.inspect end |
#proxy_context ⇒ Object
Returns the context of the proxy, same as context
.
19 20 21 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 19 def proxy_context @context end |
#proxy_owner ⇒ Object
Returns the owner of the proxy.
14 15 16 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 14 def proxy_owner @owner end |
#proxy_respond_to? ⇒ Object
3 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 3 alias_method :proxy_respond_to?, :respond_to? |
#proxy_target ⇒ Object
Returns the target of the proxy, same as target
.
24 25 26 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 24 def proxy_target @target end |
#reload ⇒ Object
Reloads the target and returns self
on success.
41 42 43 44 45 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 41 def reload @target = nil load_target self unless @target.nil? end |
#respond_to?(*args) ⇒ Boolean
Does the proxy or its target respond to symbol
?
29 30 31 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 29 def respond_to?(*args) proxy_respond_to?(*args) || (load_target && @target.respond_to?(*args)) end |
#send(method, *args) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 63 def send(method, *args) if proxy_respond_to?(method) super else reload @target.send(method, *args) end end |
#target ⇒ Object
Returns the target of this proxy, same as proxy_target
.
48 49 50 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 48 def target @target end |
#target=(target) ⇒ Object
Sets the target of this proxy to \target
, and the loaded flag to true
.
53 54 55 |
# File 'lib/scoped_tags/tag_list_proxy.rb', line 53 def target=(target) @target = target end |