popularable 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/concerns/popularable.rb +23 -9
- data/lib/popularable/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e979b1fa4cea6c06ffe15b203b29a79457c68f2
|
4
|
+
data.tar.gz: 240ec42fce12117ddaa1d22d42958013b735a336
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 271bb74de44fb2bd37196347347aae4a6fb13e7d3697ff0fb433488a5b424f61e70ee4004fbb0885d3fa8888eaff7119a838e591b464993587ac76e7c9b2104c
|
7
|
+
data.tar.gz: 713c2e4266b42a12133d87ad966f90b4a430e1abff297172e94826711740e5b6eed6361eb71297e522617582e48addb71b0e3570a6bd8d4dcfb7e6f68ecdca8a
|
data/.gitignore
CHANGED
data/lib/concerns/popularable.rb
CHANGED
@@ -5,15 +5,29 @@ 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, -> {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
scope :
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
scope :
|
8
|
+
scope :popular_today, -> {
|
9
|
+
popular_since( Time.now.beginning_of_day )
|
10
|
+
}
|
11
|
+
|
12
|
+
scope :popular_this_week, -> {
|
13
|
+
popular_since( Time.now.beginning_of_week )
|
14
|
+
}
|
15
|
+
|
16
|
+
scope :popular_this_month, -> {
|
17
|
+
popular_since( Time.now.beginning_of_month )
|
18
|
+
}
|
19
|
+
|
20
|
+
scope :popular_this_year, -> {
|
21
|
+
popular_since( Time.now.beginning_of_year )
|
22
|
+
}
|
23
|
+
|
24
|
+
scope :popular_all_time, -> {
|
25
|
+
popular_since( Time.now - 100.years )
|
26
|
+
}
|
27
|
+
|
28
|
+
scope :popular_since, -> (since){
|
29
|
+
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.to_s}')").where( "popularable_popularity_events.popularity_event_date >= ?", since.to_date ).group( "#{MediaItem.table_name}.id" ).order( "popularity DESC" )
|
30
|
+
}
|
17
31
|
|
18
32
|
has_many :popularable_popularity_events, as: :popularable
|
19
33
|
|
data/lib/popularable/version.rb
CHANGED