Class: SpudPost

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spud_post.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#spud_site_idsObject

Spud site ids getter



113
114
115
# File 'app/models/spud_post.rb', line 113

def spud_site_ids
  @spud_site_ids
end

Class Method Details

.for_spud_site(spud_site_id) ⇒ Object



25
26
27
# File 'app/models/spud_post.rb', line 25

def self.for_spud_site(spud_site_id)
	return joins(:spud_post_sites).where(:spud_post_sites => {:spud_site_id => spud_site_id})
end

.from_archive(date_string) ⇒ Object



53
54
55
56
57
58
59
60
# File 'app/models/spud_post.rb', line 53

def self.from_archive(date_string)
	begin
		date = Date.strptime(date_string, "%Y-%b")
		return where(:published_at => date..date.end_of_month)
	rescue
		return all
	end
end

.months_with_public_blog_postsObject



91
92
93
94
95
96
97
98
# File 'app/models/spud_post.rb', line 91

def self.months_with_public_blog_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 < ? AND is_news = ?', true, DateTime.now, false).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.to_s}"
	end
end

.months_with_public_news_postsObject



82
83
84
85
86
87
88
89
# File 'app/models/spud_post.rb', line 82

def self.months_with_public_news_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 < ? AND is_news = ?', true, DateTime.now, true).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.to_s}"
	end
end

.months_with_public_postsObject

Returns an array of Date objects for months with public posts



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/models/spud_post.rb', line 65

def self.months_with_public_posts
	# Select
	# 	Month(published_at) as published_month,
	# 	Year(published_at) as published_year
	# From spud_posts
	# Where visible = 1
	# And published_at < '2012-01-30'
	# Group By published_month, published_year
	# Order By published_year desc, published_month desc
	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.to_s}"
	end
end

.public_blog_posts(page, per_page) ⇒ Object



33
34
35
# File 'app/models/spud_post.rb', line 33

def self.public_blog_posts(page, per_page)
	return self.public_posts(page, per_page).where(:is_news => false)
end

.public_news_posts(page, per_page) ⇒ Object



37
38
39
# File 'app/models/spud_post.rb', line 37

def self.public_news_posts(page, per_page)
	return self.public_posts(page, per_page).where(:is_news => true)
end

.public_posts(page, per_page) ⇒ Object



29
30
31
# File 'app/models/spud_post.rb', line 29

def self.public_posts(page, per_page)
	return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').includes(:categories).paginate(:page => page, :per_page => per_page)
end

.recent_blog_posts(limit = 5) ⇒ Object



45
46
47
# File 'app/models/spud_post.rb', line 45

def self.recent_blog_posts(limit=5)
	return self.recent_posts(limit).where(:is_news => false)
end

.recent_news_posts(limit = 5) ⇒ Object



49
50
51
# File 'app/models/spud_post.rb', line 49

def self.recent_news_posts(limit=5)
	return self.recent_posts(limit).where(:is_news => true)
end

.recent_posts(limit = 5) ⇒ Object



41
42
43
# File 'app/models/spud_post.rb', line 41

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

#display_dateObject



100
101
102
# File 'app/models/spud_post.rb', line 100

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

#is_private?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'app/models/spud_post.rb', line 108

def is_private?
	return !is_public?
end

#is_public?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'app/models/spud_post.rb', line 104

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