Module: Undercarriage::Models::PublishedConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/undercarriage/models/published_concern.rb
Overview
Published
Based on the presence of a datetime in the published_at column (configurable) in the database. If there is a
datetime in the column, it is considered published. You need to do your own validation to ensure the value is a
datetime value
Class Method Summary collapse
-
.published ⇒ ActiveRecord::Relation
Published scope.
-
.unpublished ⇒ ActiveRecord::Relation
Unpublished scope.
Instance Method Summary collapse
-
#published? ⇒ Boolean
Published check.
-
#unpublished? ⇒ Boolean
Unpublished check.
Class Method Details
.published ⇒ ActiveRecord::Relation
Published scope
Retrieve only published resources
|
|
# File 'lib/undercarriage/models/published_concern.rb', line 51
|
.unpublished ⇒ ActiveRecord::Relation
Unpublished scope
Retrieve only unpublished resources
80 81 82 83 84 85 86 |
# File 'lib/undercarriage/models/published_concern.rb', line 80 included do class_attribute :published_column self.published_column = :published_at scope :published, -> { where.not(published_column => nil) } scope :unpublished, -> { where(published_column => nil) } end |
Instance Method Details
#published? ⇒ Boolean
Published check
Check if an item is published based on the presence of a value in the published column. This does not take into account whether the item is not currently available (scheduled). See module documentation for more information
99 100 101 |
# File 'lib/undercarriage/models/published_concern.rb', line 99 def published? self[self.class.published_column].present? end |
#unpublished? ⇒ Boolean
Unpublished check
Check if an item is unpublished based on the lack of presence of a value in the published column
113 114 115 |
# File 'lib/undercarriage/models/published_concern.rb', line 113 def unpublished? !published? end |