Sha256: c0b6f381659bb009410f68ddc792b9ffc2e47157f46d2511375809f784e2c5e9

Contents?: true

Size: 605 Bytes

Versions: 60

Compression:

Stored size: 605 Bytes

Contents

module Concerns
  module Publishable
    extend ActiveSupport::Concern

    included do
      scope :published, ->{ where('published_at < ?', Time.zone.now).order('published_at DESC') }
      scope :not_published, ->{ where('published_at > ? OR published_at IS NULL OR published_at = ?', Time.zone.now, '') }
    end

    def publish!(time = Time.zone.now)
      update_attribute :published_at, time
    end

    def unpublish!
      update_attribute :published_at, nil
    end

    def published?
      published_at && published_at.past?
    end

    def unpublished?
      !published?
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
udongo-6.3.1 app/models/concerns/publishable.rb
udongo-6.3.0 app/models/concerns/publishable.rb
udongo-6.2.1 app/models/concerns/publishable.rb
udongo-6.2.0 app/models/concerns/publishable.rb
udongo-6.1.0 app/models/concerns/publishable.rb
udongo-6.0.0 app/models/concerns/publishable.rb
udongo-5.9.0 app/models/concerns/publishable.rb
udongo-5.8.0 app/models/concerns/publishable.rb
udongo-5.7.0 app/models/concerns/publishable.rb
udongo-5.6.0 app/models/concerns/publishable.rb
udongo-5.5.0 app/models/concerns/publishable.rb
udongo-5.4.0 app/models/concerns/publishable.rb
udongo-5.3.1 app/models/concerns/publishable.rb
udongo-5.3.0 app/models/concerns/publishable.rb
udongo-5.2.0 app/models/concerns/publishable.rb
udongo-5.1.0 app/models/concerns/publishable.rb
udongo-5.0.2 app/models/concerns/publishable.rb
udongo-5.0.1 app/models/concerns/publishable.rb
udongo-5.0.0 app/models/concerns/publishable.rb
udongo-4.0.0 app/models/concerns/publishable.rb