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-7.9.0 app/models/concerns/publishable.rb
udongo-7.8.1 app/models/concerns/publishable.rb
udongo-7.8.0 app/models/concerns/publishable.rb
udongo-7.7.2 app/models/concerns/publishable.rb
udongo-7.7.1 app/models/concerns/publishable.rb
udongo-7.7.0 app/models/concerns/publishable.rb
udongo-7.6.2 app/models/concerns/publishable.rb
udongo-7.6.1 app/models/concerns/publishable.rb
udongo-7.6.0 app/models/concerns/publishable.rb
udongo-7.5.1 app/models/concerns/publishable.rb
udongo-7.5.0 app/models/concerns/publishable.rb
udongo-7.4.2 app/models/concerns/publishable.rb
udongo-7.4.1 app/models/concerns/publishable.rb
udongo-7.4.0 app/models/concerns/publishable.rb
udongo-7.3.5 app/models/concerns/publishable.rb
udongo-7.3.4 app/models/concerns/publishable.rb
udongo-7.3.3 app/models/concerns/publishable.rb
udongo-7.3.2 app/models/concerns/publishable.rb
udongo-7.3.1 app/models/concerns/publishable.rb
udongo-7.2.1 app/models/concerns/publishable.rb