lib/couchrest/model/designs/view.rb in couchrest_model-2.0.0.beta2 vs lib/couchrest/model/designs/view.rb in couchrest_model-2.0.0
- old
+ new
@@ -369,13 +369,14 @@
def limit_value
query[:limit]
end
- def num_pages
+ def total_pages
(total_count.to_f / limit_value).ceil
end
+ alias num_pages total_pages
def current_page
(offset_value / limit_value) + 1
end
@@ -484,15 +485,17 @@
emit(#{emit}, 1);
}
}
EOF
if opts[:reduce].nil?
- opts[:reduce] = <<-EOF
- function(key, values, rereduce) {
- return sum(values);
- }
- EOF
+ # Use built-in sum function by default
+ opts[:reduce] = "_sum"
end
+ end
+
+ if opts[:reduce].is_a?(Symbol)
+ # Assume calling a built in method, convert to a string
+ opts[:reduce] = "_#{opts[:reduce]}"
end
design_doc['views'] ||= {}
view = design_doc['views'][name.to_s] = { }
view['map'] = opts[:map]