Module: HasFinder::ActiveRecord::ClassMethods

Defined in:
lib/has_finder/has_finder.rb

Instance Method Summary collapse

Instance Method Details

#findersObject



44
45
46
47
# File 'lib/has_finder/has_finder.rb', line 44

def finders
  write_inheritable_attribute(:finders, {}) if read_inheritable_attribute(:finders).nil?
  read_inheritable_attribute(:finders)
end

#has_finder(name, options = {}, &block) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/has_finder/has_finder.rb', line 49

def has_finder(name, options = {}, &block)
  finders[name] = lambda do |parent_finder, *args|
    FinderProxy.new(parent_finder, case options
      when Hash
        options
      when Proc
        options.call(*args)
    end, &block)
  end
  meta_def(name) do |*args|
    finders[name].call(self, *args)
  end
end