Class: Spud::SpudPostModel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spud::SpudPostModel
- Includes:
- TbRedirects::HasRedirects
- Defined in:
- app/models/spud/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
37 38 39 40 |
# File 'app/models/spud/spud_post_model.rb', line 37 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
54 55 56 57 58 59 60 |
# File 'app/models/spud/spud_post_model.rb', line 54 def self.from_archive(date_string) date = Date.strptime(date_string, '%Y-%b') return where(published_at: date..date.end_of_month) rescue logger.debug 'fallback' return where('') end |
.months_with_public_posts ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/models/spud/spud_post_model.rb', line 67 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
46 47 48 |
# File 'app/models/spud/spud_post_model.rb', line 46 def self.recent_blog_posts(limit = 5) return blog_posts.recent_posts(limit) end |
.recent_news_posts(limit = 5) ⇒ Object
50 51 52 |
# File 'app/models/spud/spud_post_model.rb', line 50 def self.recent_news_posts(limit = 5) return news_posts.recent_posts(limit) end |
.recent_posts(limit = 5) ⇒ Object
42 43 44 |
# File 'app/models/spud/spud_post_model.rb', line 42 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
112 113 114 115 116 117 118 |
# File 'app/models/spud/spud_post_model.rb', line 112 def if .present? else .full_name end end |
#category_names ⇒ Object
108 109 110 |
# File 'app/models/spud/spud_post_model.rb', line 108 def category_names return categories.collect(&:name).join(', ') end |
#content_processed ⇒ Object
def content_processed=(content)
self[:content_processed] = content
end
91 92 93 94 |
# File 'app/models/spud/spud_post_model.rb', line 91 def content_processed ActiveSupport::Deprecation.warn '#content_processed is deprecated. Use #content instead.' content end |
#display_date ⇒ Object
96 97 98 |
# File 'app/models/spud/spud_post_model.rb', line 96 def display_date return published_at.strftime('%b %d, %Y') end |
#is_news ⇒ Object
62 63 64 65 |
# File 'app/models/spud/spud_post_model.rb', line 62 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
104 105 106 |
# File 'app/models/spud/spud_post_model.rb', line 104 def is_private? return !is_public? end |
#is_public? ⇒ Boolean
100 101 102 |
# File 'app/models/spud/spud_post_model.rb', line 100 def is_public? return (published_at < DateTime.now) && visible end |