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.
84 85 86 |
# File 'app/models/content.rb', line 84 def draft @draft end |
Class Method Details
.find_sti_class(type_name) ⇒ Object
7 8 9 |
# File 'app/models/content.rb', line 7 def self.find_sti_class(type_name) eval(type_name.to_s) end |
.primary ⇒ Object
63 64 65 |
# File 'app/models/content.rb', line 63 def primary published.first end |
Instance Method Details
#author_id=(author_id) ⇒ Object
89 90 91 92 |
# File 'app/models/content.rb', line 89 def () # FIXME this is only needed because belongs_to_cacheable can't be non-polymorphic, yet self. = User.find() if end |
#category_titles ⇒ Object
80 81 82 |
# File 'app/models/content.rb', line 80 def category_titles categories.collect(&:title) end |
#draft? ⇒ Boolean
102 103 104 |
# File 'app/models/content.rb', line 102 def draft? published_at.nil? end |
#just_published? ⇒ Boolean
122 123 124 |
# File 'app/models/content.rb', line 122 def just_published? published? && published_at_changed? end |
#owner ⇒ Object
76 77 78 |
# File 'app/models/content.rb', line 76 def owner section end |
#owners ⇒ Object
72 73 74 |
# File 'app/models/content.rb', line 72 def owners owner.owners << owner end |
#pending? ⇒ Boolean
106 107 108 |
# File 'app/models/content.rb', line 106 def pending? !published? end |
#published? ⇒ Boolean
110 111 112 |
# File 'app/models/content.rb', line 110 def published? !published_at.nil? && published_at <= Time.zone.now end |
#published_at=(published_at) ⇒ Object
85 86 87 |
# File 'app/models/content.rb', line 85 def published_at=(published_at) write_attribute(:published_at, draft.to_i == 1 ? nil : published_at) end |
#published_at?(date) ⇒ Boolean
114 115 116 |
# File 'app/models/content.rb', line 114 def published_at?(date) published? && date == [:year, :month, :day].map { |key| published_at.send(key).to_s } end |
#published_month ⇒ Object
98 99 100 |
# File 'app/models/content.rb', line 98 def published_month Time.local(published_at.year, published_at.month, 1) end |
#published_year ⇒ Object
94 95 96 |
# File 'app/models/content.rb', line 94 def published_year Time.local(published_at.year, 1, 1) end |
#state ⇒ Object
118 119 120 |
# File 'app/models/content.rb', line 118 def state pending? ? :pending : :published end |
#to_param ⇒ Object
68 69 70 |
# File 'app/models/content.rb', line 68 def to_param permalink end |