popularable 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87cb950ce8fbcb244d3331dcf656e052dceeaaea
4
- data.tar.gz: 26d563f2c0906f4972abd6b47d2e50f3474ed701
3
+ metadata.gz: 7e979b1fa4cea6c06ffe15b203b29a79457c68f2
4
+ data.tar.gz: 240ec42fce12117ddaa1d22d42958013b735a336
5
5
  SHA512:
6
- metadata.gz: 777d98c936990f73114222162de22048daa5525c18171cbfe2aae061d4191d03077308078e4be1312058d150b2d228bdfd6fbb8aef2a8ee8207fe4c57827fd68
7
- data.tar.gz: 94997b2e73c3cee9c47981d448f1484f124ea5bc97544475939a8acd34182f44b03e071f884c3ca418b3dcf02ef5df27ba696d852a7c0bcd763486196bf5ede3
6
+ metadata.gz: 271bb74de44fb2bd37196347347aae4a6fb13e7d3697ff0fb433488a5b424f61e70ee4004fbb0885d3fa8888eaff7119a838e591b464993587ac76e7c9b2104c
7
+ data.tar.gz: 713c2e4266b42a12133d87ad966f90b4a430e1abff297172e94826711740e5b6eed6361eb71297e522617582e48addb71b0e3570a6bd8d4dcfb7e6f68ecdca8a
data/.gitignore CHANGED
@@ -36,6 +36,7 @@ rerun.txt
36
36
  pickle-email-*.html
37
37
  .DS_Store
38
38
  *.swp
39
+ *.gem
39
40
 
40
41
  # Ignore application configuration
41
42
  /config/application.yml
@@ -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, -> { find_by_sql( ["SELECT " + self.table_name + ".*, 0 + SUM(popularable_popularity_events.popularity) AS popularity FROM " + self.table_name + " 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 >= ? GROUP BY " + self.table_name + ".id ORDER BY popularity DESC", Time.now.to_date] ) }
9
-
10
- scope :popular_this_week, -> { find_by_sql( ["SELECT " + self.table_name + ".*, 0 + SUM(popularable_popularity_events.popularity) AS popularity FROM " + self.table_name + " 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 >= ? GROUP BY " + self.table_name + ".id ORDER BY popularity DESC", Time.now.beginning_of_week.to_date] ) }
11
-
12
- scope :popular_this_month, -> { find_by_sql( ["SELECT " + self.table_name + ".*, 0 + SUM(popularable_popularity_events.popularity) AS popularity FROM " + self.table_name + " 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 >= ? GROUP BY " + self.table_name + ".id ORDER BY popularity DESC", Time.now.beginning_of_month.to_date] ) }
13
-
14
- scope :popular_this_year, -> { find_by_sql( ["SELECT " + self.table_name + ".*, 0 + SUM(popularable_popularity_events.popularity) AS popularity FROM " + self.table_name + " 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 >= ? GROUP BY " + self.table_name + ".id ORDER BY popularity DESC", Time.now.beginning_of_year.to_date] ) }
15
-
16
- scope :popular_all_time, -> { find_by_sql( ["SELECT " + self.table_name + ".*, 0 + SUM(popularable_popularity_events.popularity) AS popularity FROM " + self.table_name + " 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 + "') GROUP BY " + self.table_name + ".id ORDER BY popularity DESC"] ) }
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
 
@@ -1,5 +1,5 @@
1
1
  module Popularable
2
2
  module Rails
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff McFadden