lib/active_document/database.rb in ninjudd-active_document-0.0.4 vs lib/active_document/database.rb in ninjudd-active_document-0.0.5
- old
+ new
@@ -34,11 +34,11 @@
keys.uniq.each do |key|
if opts[:partial] and not key.kind_of?(Range)
first = [*key]
last = first + [true]
- key = first..last
+ key = first..last
end
if key == :all
cursor = db.cursor(transaction, 0)
if opts[:reverse]
@@ -63,16 +63,17 @@
# Return false once we pass the end of the range.
cond = key.exclude_end? ? lambda {|k| k < last} : lambda {|k| k <= last}
if opts[:reverse]
+ iter = lambda {cursor.get(nil, nil, Bdb::DB_PREV | flags)} # Move backward.
+
# Position the cursor at the end of the range.
- k,v = cursor.get(last, nil, Bdb::DB_SET_RANGE | flags)
+ k,v = cursor.get(last, nil, Bdb::DB_SET_RANGE | flags) || cursor.get(nil, nil, Bdb::DB_LAST | flags)
while k and not cond.call(k)
k,v = iter.call
end
- iter = lambda {cursor.get(nil, nil, Bdb::DB_PREV | flags)} # Move backward.
cond = lambda {|k| k >= first} # Change the condition to stop when we move past the start.
else
k,v = cursor.get(first, nil, Bdb::DB_SET_RANGE | flags) # Start at the beginning of the range.
iter = lambda {cursor.get(nil, nil, Bdb::DB_NEXT | flags)} # Move forward.
end