Class: TbCore::SpudPostModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- TbCore::SpudPostModel
- Includes:
- TbRedirects::HasRedirects
- Defined in:
- app/models/tb_core/spud_post_model.rb
Direct Known Subclasses
Class Method Summary collapse
- .for_spud_site(_spud_site_id) ⇒ Object
- .from_archive(date_string) ⇒ Object
- .months_with_public_posts ⇒ Object
- .recent_blog_posts(limit = 5) ⇒ Object
- .recent_news_posts(limit = 5) ⇒ Object
- .recent_posts(limit = 5) ⇒ Object
Instance Method Summary collapse
- #author_name ⇒ Object
- #category_names ⇒ Object
-
#content_processed ⇒ Object
def content_processed=(content) self = content end.
- #display_date ⇒ Object
- #is_news ⇒ Object
- #is_private? ⇒ Boolean
- #is_public? ⇒ Boolean
Class Method Details
.for_spud_site(_spud_site_id) ⇒ Object
38 39 40 41 |
# File 'app/models/tb_core/spud_post_model.rb', line 38 def self.for_spud_site(_spud_site_id) ActiveSupport::Deprecation.warn 'SpudBlog.for_spud_site is deprecated and will be removed in the future' return all() end |
.from_archive(date_string) ⇒ Object
55 56 57 58 59 60 61 |
# File 'app/models/tb_core/spud_post_model.rb', line 55 def self.from_archive(date_string) date = Date.strptime(date_string, '%Y-%b') return where(published_at: date..date.end_of_month) rescue StandardError logger.debug 'fallback' return where('') end |
.months_with_public_posts ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'app/models/tb_core/spud_post_model.rb', line 68 def self.months_with_public_posts records = SpudPost.select('Extract(Month from published_at) as published_month, Extract(Year from published_at) as published_year').where('visible = ? AND published_at < ?', true, DateTime.now).group('published_month, published_year').order('published_year desc, published_month desc') begin return records.collect { |r| Date.new(r[:published_year].to_i, r[:published_month].to_i) } rescue Exception => e logger.fatal "Exception occurred while fetching post archive dates:\n #{e}" return [] end end |
.recent_blog_posts(limit = 5) ⇒ Object
47 48 49 |
# File 'app/models/tb_core/spud_post_model.rb', line 47 def self.recent_blog_posts(limit = 5) return blog_posts.recent_posts(limit) end |
.recent_news_posts(limit = 5) ⇒ Object
51 52 53 |
# File 'app/models/tb_core/spud_post_model.rb', line 51 def self.recent_news_posts(limit = 5) return news_posts.recent_posts(limit) end |
.recent_posts(limit = 5) ⇒ Object
43 44 45 |
# File 'app/models/tb_core/spud_post_model.rb', line 43 def self.recent_posts(limit = 5) return where('visible = ? AND published_at <= ?', true, Time.now.utc).order('published_at desc').limit(limit) end |
Instance Method Details
#author_name ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'app/models/tb_core/spud_post_model.rb', line 113 def if .present? elsif .present? .full_name else '' end end |
#category_names ⇒ Object
109 110 111 |
# File 'app/models/tb_core/spud_post_model.rb', line 109 def category_names return categories.collect(&:name).join(', ') end |
#content_processed ⇒ Object
def content_processed=(content)
self[:content_processed] = content
end
92 93 94 95 |
# File 'app/models/tb_core/spud_post_model.rb', line 92 def content_processed ActiveSupport::Deprecation.warn '#content_processed is deprecated. Use #content instead.' content end |
#display_date ⇒ Object
97 98 99 |
# File 'app/models/tb_core/spud_post_model.rb', line 97 def display_date return published_at.strftime('%b %d, %Y') end |
#is_news ⇒ Object
63 64 65 66 |
# File 'app/models/tb_core/spud_post_model.rb', line 63 def is_news ActiveSupport::Deprecation.warn ':is_news is deprecated. Please rely on the :blog_key column stead.', caller return self[:is_news] end |
#is_private? ⇒ Boolean
105 106 107 |
# File 'app/models/tb_core/spud_post_model.rb', line 105 def is_private? return !is_public? end |
#is_public? ⇒ Boolean
101 102 103 |
# File 'app/models/tb_core/spud_post_model.rb', line 101 def is_public? return (published_at < DateTime.now) && visible end |