Class: Decidim::Budgets::ProjectSearch
- Inherits:
-
ResourceSearch
- Object
- ResourceSearch
- Decidim::Budgets::ProjectSearch
- Defined in:
- app/services/decidim/budgets/project_search.rb
Overview
This class handles search and filtering of projects. Needs a ‘current_component` param with a `Decidim::Component` in order to find the projects.
Instance Method Summary collapse
-
#base_query ⇒ Object
Creates the SearchLight base query.
-
#initialize(options = {}) ⇒ ProjectSearch
constructor
Public: Initializes the service.
-
#results ⇒ Object
Returns the random projects for the current page.
Constructor Details
#initialize(options = {}) ⇒ ProjectSearch
Public: Initializes the service. component - A Decidim::Component to get the projects from.
13 14 15 |
# File 'app/services/decidim/budgets/project_search.rb', line 13 def initialize( = {}) super(Project.all, ) end |
Instance Method Details
#base_query ⇒ Object
Creates the SearchLight base query.
18 19 20 21 22 23 |
# File 'app/services/decidim/budgets/project_search.rb', line 18 def base_query raise "Missing budget" unless budget raise "Missing component" unless component @scope.where(budget: budget) end |
#results ⇒ Object
Returns the random projects for the current page.
26 27 28 |
# File 'app/services/decidim/budgets/project_search.rb', line 26 def results Project.where(id: super.pluck(:id)).includes([:scope, :component, :attachments, :category]) end |