Sha256: 08f1d2d07cdfc1891e28e18335f2e73616ce9260f8246501d97d00efd9addc1e
Contents?: true
Size: 1.64 KB
Versions: 86
Compression:
Stored size: 1.64 KB
Contents
module Pageflow module EntryPublicationStates extend ActiveSupport::Concern included do scope(:published, -> { joins(:published_revision) }) scope(:published_without_password_protection, -> { published.merge(Revision.without_password_protection) }) scope(:published_with_password_protection, -> { published.merge(Revision.with_password_protection) }) scope(:not_published, lambda do includes(:published_revision) .references(:pageflow_revisions) .where(pageflow_revisions: {id: nil}) end) end def publication_state if published_with_password_protection? 'published_with_password_protection' elsif published? 'published_without_password_protection' else 'not_published' end end def published_with_password_protection? published? && published_revision.password_protected? end def published? published_revision.present? end def published_at published? ? published_revision.published_at : nil end def published_until published? ? published_revision.published_until : nil end module ClassMethods def with_publication_state(state) case state when 'published_with_password_protection' published_with_password_protection when 'published_without_password_protection' published_without_password_protection when 'not_published' not_published else fail(ArgumentError, "Unknown publication state #{state}") end end end end end
Version data entries
86 entries across 86 versions & 1 rubygems