Sha256: 8aa3010668fd28d3041093334c340975639acfaebe39222c44dd00ffbbbb123c

Contents?: true

Size: 1.37 KB

Versions: 75

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Consultations
    # This concern contains the logic related to results publication and promotion.
    module PublicableResults
      extend ActiveSupport::Concern

      class_methods do
        # Public: Scope to return only records with its results published.
        #
        # Returns an ActiveRecord::Relation.
        def results_published
          where.not(results_published_at: nil)
        end

        # Public: Scope to return only records with its results unpublished.
        #
        # Returns an ActiveRecord::Relation.
        def results_unpublished
          where(results_published_at: nil)
        end
      end

      # Public: Checks whether the record has its results published or not.
      #
      # Returns true if published, false otherwise.
      def results_published?
        results_published_at.present?
      end

      #
      # Public: Publishes the results of the given component
      #
      # Returns true if the record was properly saved, false otherwise.
      def publish_results!
        update!(results_published_at: Time.current)
      end

      #
      # Public: Unpublishes the results
      #
      # Returns true if the record was properly saved, false otherwise.
      def unpublish_results!
        update!(results_published_at: nil)
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
decidim-consultations-0.27.9 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.8 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.7 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.6 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.10 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.9 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.5 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.8 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.4 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.3 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.7 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.5 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.2 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.1 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.4 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.0 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.3 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.0.rc2 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.27.0.rc1 app/models/concerns/decidim/consultations/publicable_results.rb
decidim-consultations-0.26.2 app/models/concerns/decidim/consultations/publicable_results.rb