* Rubocop enabled style/alias * Enabled Style/ArrayJoin Cop * Enabled Style/Attr * Enabled Case Equality * Enabled CharacterLiteral * Enabled ColonMethodCall Cop * Enabled CommentAnnotation cop * Enabled PreferredHashMethods Cop * Enabled DoubleNegation Cop * Enabled EachWithObject Cop * Enabled EmptyLiteral Cop * Enabled EvenOdd Cop * Enabled IfWithSemicolon Cop * Enabled Lambda and LambdaCall Cop * Enabled LineEndConcatenation Cop * Enabled ModuleFunction Cop; * Enable NegatedIf and NegatedWhile Cop * Enabled NilComparison Cop * Enabled Not Cop * Enabled NumericLiterals Cop * Enabled OneLineConditional Cop * Enabled PercentLiteralDelimiters Cop * Excluded internal/users_controller from negated_if cop * Reverted the double negation change from github_issue_tag and github_issue.rb" * Enabled PerlBackrefs Cop * Changed Regexp.last_match(1) to Regexp.last_match(0) * Enabled proc cop * Enabled RaiseArgs Cop * Reverted Regexp.last_match(0) to Regexp.last_match(1) * Enabled SelfAssignment Cop * Enabled SingleLineMethods Cop * Enabled SpecialGlobalVars Cop * Enabled VariableInterpolation Cop * Enabled WhenThen Cop * Enabled WhileUntilModifier Cop * Enabled WordArray Cop * Enabled IfUnlessModifier Cop * Enabled GuardClause Cop
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
class StickyArticleCollection
|
|
attr_accessor :article, :author, :reaction_count_num, :comment_count_num
|
|
def initialize(article, author)
|
|
@article = article
|
|
@author = author
|
|
@reaction_count_num = Rails.env.production? ? 15 : -1
|
|
@comment_count_num = Rails.env.production? ? 7 : -2
|
|
end
|
|
|
|
def user_stickies
|
|
author.articles.
|
|
where(published: true).
|
|
limited_column_select.
|
|
tagged_with(article_tags, any: true).
|
|
where.not(id: article.id).order("published_at DESC").
|
|
limit(2)
|
|
end
|
|
|
|
def suggested_stickies
|
|
(tag_articles.load + more_articles).sample(8)
|
|
end
|
|
|
|
def tag_articles
|
|
@tag_articles ||= Article.tagged_with(article_tags, any: true).
|
|
includes(:user).
|
|
where("positive_reactions_count > ? OR comments_count > ?", reaction_count_num, comment_count_num).
|
|
where(published: true).
|
|
where.not(id: article.id, user_id: article.user_id).
|
|
where("featured_number > ?", 5.days.ago.to_i).
|
|
order("RANDOM()").
|
|
limit(8)
|
|
end
|
|
|
|
def more_articles
|
|
return [] if tag_articles.size > 6
|
|
|
|
Article.tagged_with(%w[career productivity discuss explainlikeimfive], any: true).
|
|
includes(:user).
|
|
where("comments_count > ?", comment_count_num).
|
|
where(published: true).
|
|
where.not(id: article.id, user_id: article.user_id).
|
|
where("featured_number > ?", 5.days.ago.to_i).
|
|
order("RANDOM()").
|
|
limit(10 - tag_articles.size)
|
|
end
|
|
|
|
def article_tags
|
|
@article_tags ||= article.cached_tag_list_array - ["discuss"]
|
|
end
|
|
end
|