Class: TbCore::SpudPostModel

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
TbRedirects::HasRedirects
Defined in:
app/models/tb_core/spud_post_model.rb

Direct Known Subclasses

SpudPost

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for_spud_site(_spud_site_id) ⇒ Object



35
36
37
38
# File 'app/models/tb_core/spud_post_model.rb', line 35

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



52
53
54
55
56
57
58
# File 'app/models/tb_core/spud_post_model.rb', line 52

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_postsObject



65
66
67
68
69
70
71
72
73
# File 'app/models/tb_core/spud_post_model.rb', line 65

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



44
45
46
# File 'app/models/tb_core/spud_post_model.rb', line 44

def self.recent_blog_posts(limit = 5)
  return blog_posts.recent_posts(limit)
end

.recent_news_posts(limit = 5) ⇒ Object



48
49
50
# File 'app/models/tb_core/spud_post_model.rb', line 48

def self.recent_news_posts(limit = 5)
  return news_posts.recent_posts(limit)
end

.recent_posts(limit = 5) ⇒ Object



40
41
42
# File 'app/models/tb_core/spud_post_model.rb', line 40

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_nameObject



110
111
112
113
114
115
116
117
118
# File 'app/models/tb_core/spud_post_model.rb', line 110

def author_name
  if custom_author.present?
    custom_author
  elsif author.present?
    author.full_name
  else
    ''
  end
end

#category_namesObject



106
107
108
# File 'app/models/tb_core/spud_post_model.rb', line 106

def category_names
  return categories.collect(&:name).join(', ')
end

#content_processedObject

def content_processed=(content)

self[:content_processed] = content

end



89
90
91
92
# File 'app/models/tb_core/spud_post_model.rb', line 89

def content_processed
  ActiveSupport::Deprecation.warn '#content_processed is deprecated. Use #content instead.'
  content
end

#display_dateObject



94
95
96
# File 'app/models/tb_core/spud_post_model.rb', line 94

def display_date
  return published_at.strftime('%b %d, %Y')
end

#is_newsObject



60
61
62
63
# File 'app/models/tb_core/spud_post_model.rb', line 60

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

Returns:

  • (Boolean)


102
103
104
# File 'app/models/tb_core/spud_post_model.rb', line 102

def is_private?
  return !is_public?
end

#is_public?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/models/tb_core/spud_post_model.rb', line 98

def is_public?
  return (published_at < DateTime.now) && visible
end