Class: OCms::Post
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- OCms::Post
- Defined in:
- app/models/o_cms/post.rb
Constant Summary collapse
- DRAFT_STATUS =
"draft"
- PUBLISHED_STATUS =
"published"
- SCHEDULED_STATUS =
"scheduled"
- STATUSES =
[['Draft', DRAFT_STATUS], ['Publish', PUBLISHED_STATUS], ['Schedule', SCHEDULED_STATUS]]
Instance Method Summary collapse
- #assign_attributes(new_attributes) ⇒ Object
- #create_meta_description ⇒ Object
- #create_meta_title ⇒ Object
- #create_slug ⇒ Object
- #draft? ⇒ Boolean
- #published? ⇒ Boolean
- #scheduled? ⇒ Boolean
- #status ⇒ Object
Instance Method Details
#assign_attributes(new_attributes) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/o_cms/post.rb', line 60 def assign_attributes(new_attributes) if new_attributes[:status] status = new_attributes[:status] published_at = new_attributes[:published_at] if DRAFT_STATUS == status published_at = nil elsif PUBLISHED_STATUS == status && published_at.blank? published_at = Time.current end new_attributes.delete(:status) new_attributes[:published_at] = published_at end super end |
#create_meta_description ⇒ Object
33 34 35 36 |
# File 'app/models/o_cms/post.rb', line 33 def sanitized_body = ActionView::Base.full_sanitizer.sanitize(self.body) self. = "#{sanitized_body.first(156) + ' ...'}" if self..blank? && self.body.present? end |
#create_meta_title ⇒ Object
29 30 31 |
# File 'app/models/o_cms/post.rb', line 29 def self. = "#{title}" if self..blank? && self.title.present? end |
#create_slug ⇒ Object
25 26 27 |
# File 'app/models/o_cms/post.rb', line 25 def create_slug self.slug = "#{title.parameterize}" if self.slug.blank? && self.title.present? end |
#draft? ⇒ Boolean
38 39 40 |
# File 'app/models/o_cms/post.rb', line 38 def draft? self.published_at.nil? end |
#published? ⇒ Boolean
42 43 44 |
# File 'app/models/o_cms/post.rb', line 42 def published? self.published_at.nil? ? false : self.published_at <= Time.current end |
#scheduled? ⇒ Boolean
46 47 48 |
# File 'app/models/o_cms/post.rb', line 46 def scheduled? self.published_at.nil? ? false : self.published_at > Time.current end |
#status ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'app/models/o_cms/post.rb', line 50 def status if self.draft? return DRAFT_STATUS elsif self.published? return PUBLISHED_STATUS elsif self.scheduled? return SCHEDULED_STATUS end end |