adding ducktype support

This commit is contained in:
Chris Anderson 2008-10-13 02:01:24 -07:00
parent adcaaaf59a
commit d13159039a
2 changed files with 25 additions and 3 deletions

View file

@ -273,7 +273,7 @@ module CouchRest
method_name = "by_#{keys.join('_and_')}"
self.generated_design_doc ||= default_design_doc
ducktype = opts.delete(:ducktype)
if opts[:map]
view = {}
view['map'] = opts.delete(:map)
@ -288,7 +288,7 @@ module CouchRest
key_emit = doc_keys.length == 1 ? "#{doc_keys.first}" : "[#{doc_keys.join(', ')}]"
map_function = <<-JAVASCRIPT
function(doc) {
if (doc['couchrest-type'] == '#{type}' && #{key_protection}) {
if (#{!ducktype ? "doc['couchrest-type'] == '#{type}' && " : ""}#{key_protection}) {
emit(#{key_emit}, null);
}
}