punching_bag 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,19 @@ module PunchingBag
2
2
  module ActiveRecord
3
3
 
4
4
  module ClassMethods
5
+
6
+ # Note: this method will only return items if they have 1 or more hits
5
7
  def most_hit(since=nil, limit=5)
6
8
  query = self.scoped.joins(:punches).group(:punchable_type, :punchable_id)
7
9
  query = query.where('punches.average_time >= ?', since) unless since.nil?
8
- query.order('SUM(punches.hits) DESC').limit(limit)
10
+ query.reorder('SUM(punches.hits) DESC').limit(limit)
11
+ end
12
+
13
+ # Note: this method will return all items with 0 or more hits
14
+ def sort_by_popularity(dir='DESC')
15
+ query = self.scoped.joins("LEFT OUTER JOIN punches ON punches.punchable_id = #{self.to_s.tableize}.id AND punches.punchable_type = '#{self.to_s}'")
16
+ query = query.group(:id)
17
+ query.reorder("SUM(punches.hits) #{dir}")
9
18
  end
10
19
  end
11
20
 
@@ -1,5 +1,5 @@
1
1
  module PunchingBag
2
2
 
3
- VERSION = '0.1.2'
3
+ VERSION = '0.2.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punching_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-26 00:00:00.000000000 Z
12
+ date: 2012-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: voight_kampff
16
- requirement: &76117350 !ruby/object:Gem::Requirement
16
+ requirement: &72095530 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.1.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *76117350
24
+ version_requirements: *72095530
25
25
  description: PunchingBag is a hit counting and simple trending engine for Ruby on
26
26
  Rails
27
27
  email: adam@obledesign.com
@@ -38,7 +38,7 @@ files:
38
38
  - lib/generators/punching_bag/templates/create_punches_table.rb
39
39
  - lib/punching_bag.rb
40
40
  - lib/tasks/punching_bag.rake
41
- homepage: https://github.com/adamcrown/punching_bag
41
+ homepage: https://github.com/biola/punching_bag
42
42
  licenses: []
43
43
  post_install_message:
44
44
  rdoc_options: []
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 1.8.7
61
+ rubygems_version: 1.8.16
62
62
  signing_key:
63
63
  specification_version: 3
64
64
  summary: PunchingBag hit conter and trending plugin