Sha256: 8fdba3f9c3ae427aad81ee81c4b3fbbc8346b7003c340c0809e0f465b0d1e5ca
Contents?: true
Size: 1.27 KB
Versions: 11
Compression:
Stored size: 1.27 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 def previously_published? respond_to?(:versions) && versions.where(event: "update").where("object ->> 'published_at' IS NOT NULL").any? end end end
Version data entries
11 entries across 11 versions & 1 rubygems