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
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/her_extension/model/associations/association_proxy.rb', line 11 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 |