punching_bag 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/punch.rb +12 -0
- data/lib/punching_bag/acts_as_punchable.rb +1 -1
- data/lib/punching_bag/version.rb +1 -1
- metadata +10 -5
data/app/models/punch.rb
CHANGED
@@ -91,6 +91,18 @@ class Punch < ActiveRecord::Base
|
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
+
def self.average_for(punchables)
|
95
|
+
if punchables.map(&:class).uniq.length != 1
|
96
|
+
raise ArgumentError, 'Punchables must all be of the same class'
|
97
|
+
end
|
98
|
+
|
99
|
+
sums = Punch.where(:punchable_type => punchables.first.class.to_s, :punchable_id => punchables.map(&:id)).group(:punchable_id).sum(:hits)
|
100
|
+
|
101
|
+
return 0 if sums.empty? # catch divide by zero
|
102
|
+
|
103
|
+
sums.values.inject(:+).to_f / sums.length
|
104
|
+
end
|
105
|
+
|
94
106
|
private
|
95
107
|
|
96
108
|
def set_defaults
|
@@ -35,6 +35,6 @@ class ActiveRecord::Base
|
|
35
35
|
def self.acts_as_punchable
|
36
36
|
extend PunchingBag::ActiveRecord::ClassMethods
|
37
37
|
include PunchingBag::ActiveRecord::InstanceMethods
|
38
|
-
has_many :punches, :as => :punchable
|
38
|
+
has_many :punches, :as => :punchable, :dependent => :destroy
|
39
39
|
end
|
40
40
|
end
|
data/lib/punching_bag/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.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: 2012-
|
12
|
+
date: 2012-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: voight_kampff
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 0.1.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.1
|
25
30
|
description: PunchingBag is a hit counting and simple trending engine for Ruby on
|
26
31
|
Rails
|
27
32
|
email: adam@obledesign.com
|
@@ -58,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
63
|
version: '0'
|
59
64
|
requirements: []
|
60
65
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.8.
|
66
|
+
rubygems_version: 1.8.24
|
62
67
|
signing_key:
|
63
68
|
specification_version: 3
|
64
69
|
summary: PunchingBag hit conter and trending plugin
|