Class: HasFinder::FinderProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/has_finder/has_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options, &block)
  extend options.delete(:extend) if options[:extend]
  extend Module.new(&block) if block_given?
  @proxy_finder, @proxy_scope = proxy_finder, options
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_finderObject (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_scopeObject (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

#reloadObject



13
14
15
# File 'lib/has_finder/has_finder.rb', line 13

def reload
  load_found; self
end