Sha256: d5de529c559eae5af6024512209bb67a913949bfaac2d438fe5cf7c8cfd7e0c4

Contents?: true

Size: 1.14 KB

Versions: 23

Compression:

Stored size: 1.14 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 feature
    #
    # Returns true if the record was properly saved, false otherwise.
    def publish!
      update_attribute(:published_at, Time.current)
    end

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

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
decidim-core-0.6.8 lib/decidim/publicable.rb
decidim-0.6.8 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.7 lib/decidim/publicable.rb
decidim-0.6.7 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.6 lib/decidim/publicable.rb
decidim-0.6.6 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.5 lib/decidim/publicable.rb
decidim-0.6.5 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.4 lib/decidim/publicable.rb
decidim-0.6.4 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.3 lib/decidim/publicable.rb
decidim-0.6.3 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.2 lib/decidim/publicable.rb
decidim-0.6.2 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.1 lib/decidim/publicable.rb
decidim-0.6.1 decidim-core/lib/decidim/publicable.rb
decidim-core-0.6.0 lib/decidim/publicable.rb
decidim-0.6.0 decidim-core/lib/decidim/publicable.rb
decidim-core-0.5.1 lib/decidim/publicable.rb
decidim-0.5.1 decidim-core/lib/decidim/publicable.rb