Sha256: d4523570a027e881243ad5337a007ab9a2f9ec5b005c442eaebb9280742e21c1

Contents?: true

Size: 1.3 KB

Versions: 56

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # A class used to find projects filtered by features and a date range
    class FilteredProjects < Rectify::Query
      # 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.
      def self.for(features, start_at = nil, end_at = nil)
        new(features, start_at, end_at).query
      end

      # 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.
      def initialize(features, start_at = nil, end_at = nil)
        @features = features
        @start_at = start_at
        @end_at = end_at
      end

      # Finds the Projects scoped to an array of features and filtered
      # by a range of dates.
      def query
        projects = Decidim::Budgets::Project.where(feature: @features)
        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

56 entries across 56 versions & 2 rubygems

Version Path
decidim-budgets-0.10.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.10.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.9.3 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.9.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.9.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.9.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.8.4 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.8.3 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.8.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.8.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.8.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.7.4 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.7.3 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.7.2 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.7.1 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.7.0 app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.6.8 app/queries/decidim/budgets/filtered_projects.rb
decidim-0.6.8 decidim-budgets/app/queries/decidim/budgets/filtered_projects.rb
decidim-budgets-0.6.7 app/queries/decidim/budgets/filtered_projects.rb
decidim-0.6.7 decidim-budgets/app/queries/decidim/budgets/filtered_projects.rb