Sha256: cc1f59a07abd507560e49b37399c05a8b548e06b6b9d493d596551645bcacc6f

Contents?: true

Size: 1.12 KB

Versions: 64

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

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

    class_methods do
      # Public: Scope to return only published records.
      #
      # Returns an ActiveRecord::Relation.
      def published
        where.not(published_at: nil)
      end

      # Public: Scope to return only unpublished records.
      #
      # Returns an ActiveRecord::Relation.
      def unpublished
        where(published_at: nil)
      end
    end

    # Public: Checks whether the record has been published or not.
    #
    # Returns true if published, false otherwise.
    def published?
      published_at.present?
    end

    #
    # Public: Publishes this component
    #
    # Returns true if the record was properly saved, false otherwise.
    def publish!
      update!(published_at: Time.current)
    end

    #
    # Public: Unpublishes this component
    #
    # Returns true if the record was properly saved, false otherwise.
    def unpublish!
      update!(published_at: nil)
    end
  end
end

Version data entries

64 entries across 64 versions & 1 rubygems

Version Path
decidim-core-0.26.5 lib/decidim/publicable.rb
decidim-core-0.27.2 lib/decidim/publicable.rb
decidim-core-0.27.1 lib/decidim/publicable.rb
decidim-core-0.26.4 lib/decidim/publicable.rb
decidim-core-0.27.0 lib/decidim/publicable.rb
decidim-core-0.26.3 lib/decidim/publicable.rb
decidim-core-0.27.0.rc2 lib/decidim/publicable.rb
decidim-core-0.27.0.rc1 lib/decidim/publicable.rb
decidim-core-0.26.2 lib/decidim/publicable.rb
decidim-core-0.26.1 lib/decidim/publicable.rb
decidim-core-0.26.0 lib/decidim/publicable.rb
decidim-core-0.26.0.rc2 lib/decidim/publicable.rb
decidim-core-0.26.0.rc1 lib/decidim/publicable.rb
decidim-core-0.25.2 lib/decidim/publicable.rb
decidim-core-0.25.1 lib/decidim/publicable.rb
decidim-core-0.25.0 lib/decidim/publicable.rb
decidim-core-0.25.0.rc4 lib/decidim/publicable.rb
decidim-core-0.25.0.rc3 lib/decidim/publicable.rb
decidim-core-0.25.0.rc2 lib/decidim/publicable.rb
decidim-core-0.25.0.rc1 lib/decidim/publicable.rb