Class: Her::Model::Associations::AssociationProxy
- Inherits:
-
Object
- Object
- Her::Model::Associations::AssociationProxy
- Defined in:
- lib/her_extension/model/associations/association_proxy.rb
Instance Method Summary collapse
-
#loaded? ⇒ Boolean
Returns true if the association has been loaded, otherwise false.
- #method_missing(name, *args, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/her_extension/model/associations/association_proxy.rb', line 15 def method_missing(name, *args, &block) if :object_id == name # avoid redefining object_id return association.fetch.object_id end # Check if a class scope has previously been defined begin if Relation.scopes.keys.grep(::Regexp.new(name.to_s)).any? return self.association.send(name,*args,&block) end rescue ::NoMethodError => e end # create a proxy to the fetched object's method # https://github.com/remiprev/her/pull/377 AssociationProxy.install_proxy_methods 'association.fetch', name # resend message to fetched object __send__(name, *args, &block) end |
Instance Method Details
#loaded? ⇒ Boolean
Returns true if the association has been loaded, otherwise false.
11 12 13 |
# File 'lib/her_extension/model/associations/association_proxy.rb', line 11 def loaded? !!association.instance_variable_get('@cached_result') end |