Class: PopularPosts
- Inherits:
-
Object
- Object
- PopularPosts
- Defined in:
- app/services/popular_posts.rb
Overview
Getting popular posts
Class Method Summary collapse
- .month(count) ⇒ Object
- .overall(count) ⇒ Object
- .post_type_ids ⇒ Object
- .prepare(count = 5) ⇒ Object
- .week(count) ⇒ Object
Class Method Details
.month(count) ⇒ Object
21 22 23 |
# File 'app/services/popular_posts.rb', line 21 def self.month(count) Post.visible.where(post_type_id: post_type_ids).where('created_at > ?', 1.month.ago).popular.first(count) end |
.overall(count) ⇒ Object
25 26 27 |
# File 'app/services/popular_posts.rb', line 25 def self.overall(count) Post.visible.where(post_type_id: post_type_ids).popular.first(count) end |
.post_type_ids ⇒ Object
5 6 7 |
# File 'app/services/popular_posts.rb', line 5 def self.post_type_ids PostType.where(slug: %w[news article]).pluck(:id) end |
.prepare(count = 5) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/services/popular_posts.rb', line 9 def self.prepare(count = 5) { week: week(count), month: month(count), overall: overall(count) } end |
.week(count) ⇒ Object
17 18 19 |
# File 'app/services/popular_posts.rb', line 17 def self.week(count) Post.visible.where(post_type_id: post_type_ids).where('created_at > ?', 7.days.ago).popular.first(count) end |