made the pager return keys in order

This commit is contained in:
Chris Anderson 2008-08-27 18:45:51 -07:00
parent fbccbd73e0
commit 15884184aa

View file

@ -75,13 +75,27 @@ class CouchRest
startkey = endkey startkey = endkey
end end
grouped = rows.group_by{|r|r['key']} # grouped = rows.group_by{|r|r['key']}
grouped.each do |k, rs| # grouped.each do |k, rs|
vs = rs.collect{|r|r['value']} # vs = rs.collect{|r|r['value']}
yield(k,vs) # yield(k,vs)
end # end
key = :begin
values = []
rows.each do |r|
if key != r['key']
# we're on a new key, yield the old first and then reset
yield(key, values) if key != :begin
key = r['key']
values = []
end
# keep accumulating
values << r['value']
end
yield(key, values)
# lastprocessedkey = rows.last['key']
end end
end end