Sha256: 753ebfe93c506a699dbfadd4c9d1d94815a392719ccbe6fe9a3b3696f47feb5e
Contents?: true
Size: 935 Bytes
Versions: 15
Compression:
Stored size: 935 Bytes
Contents
module Mongoid module Contexts module Ids # Return documents based on an id search. Will handle if a single id has # been passed or mulitple ids. # # Example: # # context.id_criteria([1, 2, 3]) # # Returns: # # The single or multiple documents. def id_criteria(params) criteria.id(strings_to_object_ids(params)) params.is_a?(Array) ? criteria.entries : one end protected # Convert ids from strings to +BSON::ObjectID+s def strings_to_object_ids(ids) if Array === ids ids.map {|id| string_to_object_id(id) } else string_to_object_id(ids) end end # Convert ids from strings to +BSON::ObjectID+s def string_to_object_id(id) if String === id ::BSON::ObjectID.from_string(id) else id end end end end end
Version data entries
15 entries across 15 versions & 2 rubygems