Method: MongoMapper::Document::ClassMethods#find!

Defined in:
lib/mongo_mapper/document.rb

#find(: first, options) ⇒ Object #find(: last, options) ⇒ Object #find(: all, options) ⇒ Object #find(ids, options) ⇒ Object

Overloads:

  • #find(: first, options) ⇒ Object

    See Also:

    • Document.first
  • #find(: last, options) ⇒ Object

    See Also:

    • Document.last
  • #find(: all, options) ⇒ Object

    See Also:

    • Document.all

Raises:

  • DocumentNotFound raised when no ID or arguments are provided



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mongo_mapper/document.rb', line 58

def find!(*args)
  options = args.extract_options!
  case args.first
    when :first then first(options)
    when :last  then last(options)
    when :all   then find_every(options)
    when Array  then find_some(args, options)
    else
      case args.size
        when 0
          raise DocumentNotFound, "Couldn't find without an ID"
        when 1
          find_one!(options.merge({:_id => args[0]}))
        else
          find_some(args, options)
      end
  end
end