popularable 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/concerns/popularable.rb +13 -13
- data/lib/popularable/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '064497b0e513cb12f5576493808768c138dc33ad745b23c5b7091c45ac078987'
|
4
|
+
data.tar.gz: ea65be967f9c675cdff2bea3f0ecbf6364e9642cc0311728d87c56a0ec1e41f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c911cac3ce70dea9760a520296c2c538655371047028dff2094cb4710eb0362790366549f419633a57b33fe89d4737a577b43911882cb9c802956ba032dca5b
|
7
|
+
data.tar.gz: 043eb3b48552d0e2d70fc4af001e3570e002419158915a2bfe9a87f94a6ae0d427238bb0f0edcec7acc8df22ceea834f026c5e6519b1e98fa207325b111180ea
|
data/lib/concerns/popularable.rb
CHANGED
@@ -5,27 +5,27 @@ module Popularable
|
|
5
5
|
included do
|
6
6
|
# scope :order_by_recent_popularity, -> { .joins( "LEFT OUTER JOIN popularable_popularity_events ON (" + self.to_s.pluralize.underscore + ".id = popularable_popularity_events.popularable_id AND popularable_popularity_events.popularable_type = '" + self.to_s + "')").where( ["popularable_popularity_events.popularity_event_date >= ?", 1.month.ago] ).group( self.to_s.pluralize.underscore + ".id" ).order( "popularity DESC" ) }
|
7
7
|
|
8
|
-
scope :popular_today, -> {
|
8
|
+
scope :popular_today, -> {
|
9
9
|
popular_since( Time.now.beginning_of_day )
|
10
10
|
}
|
11
11
|
|
12
|
-
scope :popular_this_week, -> {
|
12
|
+
scope :popular_this_week, -> {
|
13
13
|
popular_since( Time.now.beginning_of_week )
|
14
14
|
}
|
15
|
-
|
16
|
-
scope :popular_this_month, -> {
|
15
|
+
|
16
|
+
scope :popular_this_month, -> {
|
17
17
|
popular_since( Time.now.beginning_of_month )
|
18
18
|
}
|
19
|
-
|
20
|
-
scope :popular_this_year, -> {
|
19
|
+
|
20
|
+
scope :popular_this_year, -> {
|
21
21
|
popular_since( Time.now.beginning_of_year )
|
22
22
|
}
|
23
23
|
|
24
|
-
scope :popular_all_time, -> {
|
24
|
+
scope :popular_all_time, -> {
|
25
25
|
# This uses an inner join and ditches the unnecessary where clause for performance.
|
26
26
|
select( "#{self.table_name}.*, 0 + SUM(popularable_popularity_events.popularity) AS popularity").joins( "INNER JOIN popularable_popularity_events ON (#{self.table_name}.id = popularable_popularity_events.popularable_id AND popularable_popularity_events.popularable_type = '#{self.name}')").group( "#{self.table_name}.id" ).order( "popularity DESC" )
|
27
27
|
}
|
28
|
-
|
28
|
+
|
29
29
|
scope :popular_since, -> (since){
|
30
30
|
select( "#{self.table_name}.*, 0 + SUM(popularable_popularity_events.popularity) AS popularity").joins( "LEFT OUTER JOIN popularable_popularity_events ON (#{self.table_name}.id = popularable_popularity_events.popularable_id AND popularable_popularity_events.popularable_type = '#{self.name}')").where( "popularable_popularity_events.popularity_event_date >= ?", since.to_date ).group( "#{self.table_name}.id" ).order( "popularity DESC" )
|
31
31
|
}
|
@@ -35,7 +35,7 @@ module Popularable
|
|
35
35
|
def self.has_popularable_concern?
|
36
36
|
true
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
# Count methods
|
40
40
|
def popular_count_today
|
41
41
|
popular_count_since(Time.now.beginning_of_day)
|
@@ -57,16 +57,16 @@ module Popularable
|
|
57
57
|
popular_count_since(Time.now - 100.years)
|
58
58
|
end
|
59
59
|
|
60
|
-
def popular_count_since(since = Time.now)
|
60
|
+
def popular_count_since(since = Time.now)
|
61
61
|
popularable_popularity_events.where( "popularable_popularity_events.popularity_event_date >= ?", since.to_date ).sum( :popularity )
|
62
|
-
end
|
62
|
+
end
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def bump_popularity!( popularity_add_value = 1, popularity_event_time = Time.now )
|
67
67
|
popularable_popularity_event = self.popularable_popularity_events.find_or_create_by( popularity_event_date: popularity_event_time.to_date )
|
68
68
|
|
69
|
-
popularable_popularity_event.
|
69
|
+
popularable_popularity_event.update( popularity: popularable_popularity_event.popularity.to_i + popularity_add_value )
|
70
70
|
end
|
71
71
|
end
|
72
|
-
end
|
72
|
+
end
|
data/lib/popularable/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popularable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff McFadden
|
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.5.1
|
79
|
+
rubygems_version: 3.0.3
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
82
|
summary: Organize your models by a historical popularity value
|