Class: Guacamole::Proxies::Proxy
- Inherits:
- BasicObject
- Defined in:
- lib/guacamole/proxies/proxy.rb
Overview
This is the base class for the association proxies. Proxies are only needed for non-embedded relations between objects. Embedded objects are taken care of by Virtus.
The Proxy
class undefines most methods and passes them to the
@target
. The @target
will be a lambda which will lazy query the
requested objects from the database.
Concrete proxy classes are:
- ReferencedBy: This will handle one-to-many associations
- References: This will handle many-to-one associations
Direct Known Subclasses
Instance Method Summary collapse
-
#init(base, target) ⇒ Object
Convenience method to setup the proxy.
- #method_missing(meth, *args, &blk) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
- #target ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
33 34 35 |
# File 'lib/guacamole/proxies/proxy.rb', line 33 def method_missing(meth, *args, &blk) target.call.send meth, *args, &blk end |
Instance Method Details
#init(base, target) ⇒ Object
Convenience method to setup the proxy. The subclasses need to care of creating
the target
correctly.
28 29 30 31 |
# File 'lib/guacamole/proxies/proxy.rb', line 28 def init(base, target) @base = base @target = target end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
37 38 39 |
# File 'lib/guacamole/proxies/proxy.rb', line 37 def respond_to_missing?(name, include_private = false) target.respond_to?(name, include_private) end |
#target ⇒ Object
41 42 43 |
# File 'lib/guacamole/proxies/proxy.rb', line 41 def target @target || ->() { nil } end |