Class: Decidim::Debates::DebateSearch

Inherits:
ResourceSearch
  • Object
show all
Defined in:
app/services/decidim/debates/debate_search.rb

Overview

This class handles search and filtering of debates. Needs a ‘current_component` param with a `Decidim::Component` in order to find the debates.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DebateSearch

Public: Initializes the service. component - A Decidim::Component to get the debates from. page - The page number to paginate the results. per_page - The number of debates to return per page.



15
16
17
# File 'app/services/decidim/debates/debate_search.rb', line 15

def initialize(options = {})
  super(Debate.not_hidden, options)
end

Instance Method Details

#search_activityObject

Handle the activity filter



20
21
22
23
24
25
26
27
28
29
# File 'app/services/decidim/debates/debate_search.rb', line 20

def search_activity
  case activity
  when "commented"
    query.commented_by(user)
  when "my_debates"
    query.authored_by(user)
  else # Assume 'all'
    query
  end
end

#search_stateObject

Handle the state filter



32
33
34
# File 'app/services/decidim/debates/debate_search.rb', line 32

def search_state
  apply_scopes(%w(open closed), state)
end