Files
nairobi/lib/merged_comment_tree.rb
Javi Martín 7b5ce80593 Simplify MergedCommentTree#initialize
By setting the comments lazily in a different method, we can share its
code with the parent class.
2019-05-29 20:50:53 +02:00

25 lines
600 B
Ruby

class MergedCommentTree < CommentTree
attr_reader :commentables, :array_order
def initialize(commentables, page, order = "confidence_score")
@commentables = commentables
super(commentables.first, page, order)
@array_order = set_array_order(order)
end
def root_comments
Kaminari.paginate_array(commentables.flatten.map(&:comments).map(&:roots).flatten.sort_by {|a| a[array_order]}.reverse).
page(page).per(ROOT_COMMENTS_PER_PAGE)
end
def set_array_order(order)
case order
when "newest"
"created_at"
else
"confidence_score"
end
end
end