Class: Content
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Content
- Includes:
- Adva::BelongsToAuthor, Adva::HasPermalink
- Defined in:
- app/models/content.rb
Instance Attribute Summary collapse
-
#draft ⇒ Object
Returns the value of attribute draft.
Class Method Summary collapse
Instance Method Summary collapse
- #author_id=(author_id) ⇒ Object
- #category_titles ⇒ Object
- #draft? ⇒ Boolean
- #just_published? ⇒ Boolean
- #owner ⇒ Object
- #owners ⇒ Object
- #pending? ⇒ Boolean
- #published? ⇒ Boolean
- #published_at=(published_at) ⇒ Object
- #published_at?(date) ⇒ Boolean
- #published_month ⇒ Object
- #published_year ⇒ Object
- #state ⇒ Object
- #to_param ⇒ Object
Methods included from Adva::BelongsToAuthor
Methods included from Adva::HasPermalink
Instance Attribute Details
#draft ⇒ Object
Returns the value of attribute draft.
77 78 79 |
# File 'app/models/content.rb', line 77 def draft @draft end |
Class Method Details
.primary ⇒ Object
56 57 58 |
# File 'app/models/content.rb', line 56 def primary published.first end |
Instance Method Details
#author_id=(author_id) ⇒ Object
82 83 84 85 |
# File 'app/models/content.rb', line 82 def () # FIXME this is only needed because belongs_to_cacheable can't be non-polymorphic, yet self. = User.find() if end |
#category_titles ⇒ Object
73 74 75 |
# File 'app/models/content.rb', line 73 def category_titles categories.collect(&:title) end |
#draft? ⇒ Boolean
95 96 97 |
# File 'app/models/content.rb', line 95 def draft? published_at.nil? end |
#just_published? ⇒ Boolean
115 116 117 |
# File 'app/models/content.rb', line 115 def just_published? published? && published_at_changed? end |
#owner ⇒ Object
69 70 71 |
# File 'app/models/content.rb', line 69 def owner section end |
#owners ⇒ Object
65 66 67 |
# File 'app/models/content.rb', line 65 def owners owner.owners << owner end |
#pending? ⇒ Boolean
99 100 101 |
# File 'app/models/content.rb', line 99 def pending? !published? end |
#published? ⇒ Boolean
103 104 105 |
# File 'app/models/content.rb', line 103 def published? !published_at.nil? && published_at <= Time.zone.now end |
#published_at=(published_at) ⇒ Object
78 79 80 |
# File 'app/models/content.rb', line 78 def published_at=(published_at) write_attribute(:published_at, draft.to_i == 1 ? nil : published_at) end |
#published_at?(date) ⇒ Boolean
107 108 109 |
# File 'app/models/content.rb', line 107 def published_at?(date) published? && date == [:year, :month, :day].map { |key| published_at.send(key).to_s } end |
#published_month ⇒ Object
91 92 93 |
# File 'app/models/content.rb', line 91 def published_month Time.local(published_at.year, published_at.month, 1) end |
#published_year ⇒ Object
87 88 89 |
# File 'app/models/content.rb', line 87 def published_year Time.local(published_at.year, 1, 1) end |
#state ⇒ Object
111 112 113 |
# File 'app/models/content.rb', line 111 def state pending? ? :pending : :published end |
#to_param ⇒ Object
61 62 63 |
# File 'app/models/content.rb', line 61 def to_param permalink end |