Module: ConcernsOnRails::Models::Publishable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/concerns_on_rails/models/publishable.rb
Instance Method Summary collapse
-
#draft? ⇒ Boolean
Never set — a true draft.
-
#publish! ⇒ Object
Instance methods Publish the record Example: record.publish!.
-
#publish_at!(time) ⇒ Object
Publish at an explicit time.
-
#published? ⇒ Boolean
Check if the record is published Example: record.published?.
-
#scheduled? ⇒ Boolean
Set, but the publish time is still in the future.
-
#unpublish! ⇒ Object
Unpublish the record Example: record.unpublish!.
-
#unpublished? ⇒ Boolean
Check if the record is unpublished Example: record.unpublished?.
Instance Method Details
#draft? ⇒ Boolean
Never set — a true draft.
84 85 86 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 84 def draft? self[self.class.publishable_field].blank? end |
#publish! ⇒ Object
Instance methods Publish the record Example:
record.publish!
47 48 49 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 47 def publish! update(self.class.publishable_field => Time.zone.now) end |
#publish_at!(time) ⇒ Object
Publish at an explicit time. A future time schedules the record. Example:
record.publish_at!(1.day.from_now)
91 92 93 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 91 def publish_at!(time) update(self.class.publishable_field => time) end |
#published? ⇒ Boolean
Check if the record is published Example:
record.published?
61 62 63 64 65 66 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 61 def published? value = self[self.class.publishable_field] return false unless value.present? value.respond_to?(:<=) ? value <= Time.zone.now : true end |
#scheduled? ⇒ Boolean
Set, but the publish time is still in the future.
76 77 78 79 80 81 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 76 def scheduled? value = self[self.class.publishable_field] return false if value.blank? value.respond_to?(:>) ? value > Time.zone.now : false end |
#unpublish! ⇒ Object
Unpublish the record Example:
record.unpublish!
54 55 56 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 54 def unpublish! update(self.class.publishable_field => nil) end |
#unpublished? ⇒ Boolean
Check if the record is unpublished Example:
record.unpublished?
71 72 73 |
# File 'lib/concerns_on_rails/models/publishable.rb', line 71 def unpublished? !published? end |