Class: Collavre::Creatives::Filters::CommentFilter

Inherits:
BaseFilter
  • Object
show all
Defined in:
app/services/collavre/creatives/filters/comment_filter.rb

Instance Method Summary collapse

Methods inherited from BaseFilter

#initialize

Constructor Details

This class inherits a constructor from Collavre::Creatives::Filters::BaseFilter

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'app/services/collavre/creatives/filters/comment_filter.rb', line 5

def active?
  params[:has_comments].present? || params[:comment].present?
end

#matchObject



9
10
11
12
13
14
15
16
17
# File 'app/services/collavre/creatives/filters/comment_filter.rb', line 9

def match
  has_comments = params[:has_comments] == "true" || params[:comment] == "true"

  if has_comments
    scope.joins(:comments).distinct.pluck(:id)
  else
    scope.left_joins(:comments).where(comments: { id: nil }).pluck(:id)
  end
end