Class: Decidim::Proposals::FilteredProposals

Inherits:
Rectify::Query
  • Object
show all
Defined in:
decidim-proposals/app/queries/decidim/proposals/filtered_proposals.rb

Overview

A class used to find proposals filtered by features and a date range

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(features, start_at = nil, end_at = nil) ⇒ FilteredProposals

Initializes the class.

features - An array of Decidim::Feature start_at - A date to filter resources created after it end_at - A date to filter resources created before it.



20
21
22
23
24
# File 'decidim-proposals/app/queries/decidim/proposals/filtered_proposals.rb', line 20

def initialize(features, start_at = nil, end_at = nil)
  @features = features
  @start_at = start_at
  @end_at = end_at
end

Class Method Details

.for(features, start_at = nil, end_at = nil) ⇒ Object

Syntactic sugar to initialize the class and return the queried objects.

features - An array of Decidim::Feature start_at - A date to filter resources created after it end_at - A date to filter resources created before it.



11
12
13
# File 'decidim-proposals/app/queries/decidim/proposals/filtered_proposals.rb', line 11

def self.for(features, start_at = nil, end_at = nil)
  new(features, start_at, end_at).query
end

Instance Method Details

#queryObject

Finds the Proposals scoped to an array of features and filtered by a range of dates.



28
29
30
31
32
33
# File 'decidim-proposals/app/queries/decidim/proposals/filtered_proposals.rb', line 28

def query
  proposals = Decidim::Proposals::Proposal.where(feature: @features)
  proposals = proposals.where("created_at >= ?", @start_at) if @start_at.present?
  proposals = proposals.where("created_at <= ?", @end_at) if @end_at.present?
  proposals
end