Class: HasFinder::FinderProxy
Instance Attribute Summary collapse
-
#proxy_finder ⇒ Object
readonly
Returns the value of attribute proxy_finder.
-
#proxy_scope ⇒ Object
readonly
Returns the value of attribute proxy_scope.
Instance Method Summary collapse
-
#initialize(proxy_finder, options, &block) ⇒ FinderProxy
constructor
A new instance of FinderProxy.
- #reload ⇒ Object
Constructor Details
#initialize(proxy_finder, options, &block) ⇒ FinderProxy
Returns a new instance of FinderProxy.
7 8 9 10 11 |
# File 'lib/has_finder/has_finder.rb', line 7 def initialize(proxy_finder, , &block) extend .delete(:extend) if [:extend] extend Module.new(&block) if block_given? @proxy_finder, @proxy_scope = proxy_finder, end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
23 24 25 26 27 28 29 30 31 |
# File 'lib/has_finder/has_finder.rb', line 23 def method_missing(method, *args, &block) if finders.include?(method) finders[method].call(self, *args) else with_scope :find => proxy_scope do proxy_finder.send(method, *args, &block) end end end |
Instance Attribute Details
#proxy_finder ⇒ Object (readonly)
Returns the value of attribute proxy_finder.
3 4 5 |
# File 'lib/has_finder/has_finder.rb', line 3 def proxy_finder @proxy_finder end |
#proxy_scope ⇒ Object (readonly)
Returns the value of attribute proxy_scope.
3 4 5 |
# File 'lib/has_finder/has_finder.rb', line 3 def proxy_scope @proxy_scope end |
Instance Method Details
#reload ⇒ Object
13 14 15 |
# File 'lib/has_finder/has_finder.rb', line 13 def reload load_found; self end |