lib/mongodoc/criteria.rb in mongodoc-0.2.1 vs lib/mongodoc/criteria.rb in mongodoc-0.2.2

- old
+ new

@@ -99,15 +99,16 @@ # # <tt>criteria.each { |doc| p doc }</tt> def each(&block) @collection ||= execute if block_given? - @collection = collection.inject([]) do |container, item| + container = [] + collection.each do |item| container << item yield item - container end + @collection = container end self end GROUP_REDUCE = "function(obj, prev) { prev.group.push(obj); }" @@ -164,13 +165,14 @@ # # <tt>criteria.criteria(:where => { :field => "value"}, :limit => 20)</tt> # # Returns <tt>self</tt> def criteria(criteria_conditions = {}) - criteria_conditions.inject(self) do |criteria, (key, value)| - criteria.send(key, value) + criteria_conditions.each do |(key, value)| + send(key, value) end + self end # Adds a criterion to the +Criteria+ that specifies values that must all # be matched in order to return results. Similar to an "in" clause but the # underlying conditional logic is an "AND" and not an "OR". The MongoDB @@ -240,9 +242,12 @@ # # <tt>criteria.id("4ab2bc4b8ad548971900005c")</tt> # # Returns: <tt>self</tt> def id(id_or_object_id) + if id_or_object_id.kind_of?(String) + id_or_object_id = Mongo::ObjectID.from_string(id_or_object_id) + end selector[:_id] = id_or_object_id; self end # Adds a criterion to the +Criteria+ that specifies values where any can # be matched in order to return results. This is similar to an SQL "IN"