Module: Mongoid::Finders
- Defined in:
- lib/mongoid_dynamic_finder/finder.rb
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *arguments, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/mongoid_dynamic_finder/finder.rb', line 4 def method_missing(method_id, *arguments, &block) conditions = {} case method_id.to_s when /^find_(all|last||first)_?by_([_a-zA-Z]\w*)$/ finder_type = !$1.blank? ? $1.to_sym : :all $2.split(/_and_/).each_with_index do |attr, i| conditions[attr] = arguments[i] end find(finder_type, :conditions => conditions) else super end end |