Skip to content

Instantly share code, notes, and snippets.

@lennart
Created November 25, 2009 08:06
Show Gist options
  • Select an option

  • Save lennart/242555 to your computer and use it in GitHub Desktop.

Select an option

Save lennart/242555 to your computer and use it in GitHub Desktop.
def self.with_replies(id, options = {})
options.merge!(:startkey => [id], :endkey => [id,{}], :raw => true, :include_docs => true)
#by_replies calls the view with map_hierarchy.js as the map function
raw_replies = by_replies(options)
return [] if raw_replies.empty?
class_eval do
raw_replies["rows"].map do |row|
if row["key"].size == 1
new(row["doc"])
else
[(row["key"].size-1) / 2,new(row["doc"])]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment