Class: Chive::Article
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Chive::Article
- Defined in:
- app/models/chive/article.rb
Class Method Summary collapse
Instance Method Summary collapse
- #byline ⇒ Object
- #draft? ⇒ Boolean
- #expired? ⇒ Boolean
- #pending? ⇒ Boolean
- #public? ⇒ Boolean
- #published? ⇒ Boolean
- #real_author_name ⇒ Object
- #set_slug ⇒ Object
- #to_param ⇒ Object
Class Method Details
.latest ⇒ Object
58 59 60 |
# File 'app/models/chive/article.rb', line 58 def self.latest self.order(published_at: :desc, created_at: :desc) end |
.latest_published ⇒ Object
62 63 64 65 |
# File 'app/models/chive/article.rb', line 62 def self.latest_published now = DateTime.now latest.where('published_at <= ? AND (expired_at >= ? OR expired_at IS NULL) AND status = ?', now, now, 'publish') end |
Instance Method Details
#byline ⇒ Object
20 21 22 23 24 |
# File 'app/models/chive/article.rb', line 20 def return if .present? return if .present? Chive.anonymous_name end |
#draft? ⇒ Boolean
42 43 44 |
# File 'app/models/chive/article.rb', line 42 def draft? self.status == 'draft' end |
#expired? ⇒ Boolean
34 35 36 |
# File 'app/models/chive/article.rb', line 34 def expired? expired_at && expired_at <= DateTime.now end |
#pending? ⇒ Boolean
30 31 32 |
# File 'app/models/chive/article.rb', line 30 def pending? published_at > DateTime.now end |
#public? ⇒ Boolean
46 47 48 |
# File 'app/models/chive/article.rb', line 46 def public? self.status == 'publish' && !pending? && !expired? end |
#published? ⇒ Boolean
38 39 40 |
# File 'app/models/chive/article.rb', line 38 def published? self.status == 'publish' end |
#real_author_name ⇒ Object
26 27 28 |
# File 'app/models/chive/article.rb', line 26 def .present? && .send(Chive.user_name_attr) end |
#set_slug ⇒ Object
54 55 56 |
# File 'app/models/chive/article.rb', line 54 def set_slug self.slug = Chive.slug_formatter.call(self) if slug.blank? end |
#to_param ⇒ Object
50 51 52 |
# File 'app/models/chive/article.rb', line 50 def to_param slug end |