Simplify MergedCommentTree#initialize
By setting the comments lazily in a different method, we can share its code with the parent class.
This commit is contained in:
@@ -2,14 +2,17 @@ class CommentTree
|
|||||||
|
|
||||||
ROOT_COMMENTS_PER_PAGE = 10
|
ROOT_COMMENTS_PER_PAGE = 10
|
||||||
|
|
||||||
attr_accessor :root_comments, :comments, :commentable, :page, :order
|
attr_reader :root_comments, :commentable, :page, :order
|
||||||
|
|
||||||
def initialize(commentable, page, order = "confidence_score", valuations: false)
|
def initialize(commentable, page, order = "confidence_score", valuations: false)
|
||||||
@commentable = commentable
|
@commentable = commentable
|
||||||
@page = page
|
@page = page
|
||||||
@order = order
|
@order = order
|
||||||
@valuations = valuations
|
@valuations = valuations
|
||||||
@comments = root_comments + root_descendants
|
end
|
||||||
|
|
||||||
|
def comments
|
||||||
|
@comments ||= root_comments + root_descendants
|
||||||
end
|
end
|
||||||
|
|
||||||
def root_comments
|
def root_comments
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
class MergedCommentTree < CommentTree
|
class MergedCommentTree < CommentTree
|
||||||
attr_accessor :commentables, :array_order
|
attr_reader :commentables, :array_order
|
||||||
|
|
||||||
def initialize(commentables, page, order = "confidence_score")
|
def initialize(commentables, page, order = "confidence_score")
|
||||||
@commentables = commentables
|
@commentables = commentables
|
||||||
@commentable = commentables.first
|
super(commentables.first, page, order)
|
||||||
@page = page
|
|
||||||
@order = order
|
|
||||||
@array_order = set_array_order(order)
|
@array_order = set_array_order(order)
|
||||||
|
|
||||||
@comments = root_comments + root_descendants
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def root_comments
|
def root_comments
|
||||||
|
|||||||
Reference in New Issue
Block a user