Sha256: 156809cde2c6be0d8d9e6c8d4cddbc6c587ad4c41a349f8d916b25087a765a17

Contents?: true

Size: 1.32 KB

Versions: 30

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A class used to find projects filtered by components and a date range
    class FilteredProjects < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def self.for(components, start_at = nil, end_at = nil)
        new(components, start_at, end_at).query
      end

      # Initializes the class.
      #
      # components - An array of Decidim::Component
      # start_at - A date to filter resources created after it
      # end_at - A date to filter resources created before it.
      def initialize(components, start_at = nil, end_at = nil)
        @components = components
        @start_at = start_at
        @end_at = end_at
      end

      # Finds the Projects scoped to an array of components and filtered
      # by a range of dates.
      def query
        projects = Decidim::Budgets::Project.where(component: @components)
        projects = projects.where("created_at >= ?", @start_at) if @start_at.present?
        projects = projects.where("created_at <= ?", @end_at) if @end_at.present?
        projects
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-budgets-0.22.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.21.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.20.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.20.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.19.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.18.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.19.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.17.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.18.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.17.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.16.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.17.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.16.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.15.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.15.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.15.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.14.4 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.14.3 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.14.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.14.1 app/queries/decidim/budgets/filtered_projects.rb