punching_bag 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/models/punch.rb +9 -11
- data/lib/generators/punching_bag/templates/create_punches_table.rb +1 -1
- data/lib/punching_bag.rb +3 -4
- data/lib/punching_bag/acts_as_punchable.rb +4 -4
- data/lib/punching_bag/acts_as_taggable_on.rb +1 -1
- data/lib/punching_bag/version.rb +1 -1
- metadata +33 -55
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ad93dc4871a77426b80b0eb6803e7fef923aeb1
|
4
|
+
data.tar.gz: 665d375e9249f8323639059227faa647ba105097
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ac6a0df00b0af20ba4057b652d9aa9719fa28163d5a040186354ed06632fc6a3ba353d2df79649a805d7f02f8ec33487e7c315a23ae6c2c9d2e0bbe5576850e8
|
7
|
+
data.tar.gz: 6441dc791b6369cbcbf661002c3b77939820e3f37e30bcd3676182c0f1bb7a7af9ef54eddeed490f42f9df69980534739a79e7a8ec4080a942ba72e48315a7ca
|
data/app/models/punch.rb
CHANGED
@@ -2,8 +2,6 @@ class Punch < ActiveRecord::Base
|
|
2
2
|
|
3
3
|
belongs_to :punchable, :polymorphic => true
|
4
4
|
|
5
|
-
attr_accessible # none
|
6
|
-
|
7
5
|
before_validation :set_defaults
|
8
6
|
validates :punchable_id, :punchable_type, :starts_at, :ends_at, :average_time, :hits, :presence => true
|
9
7
|
|
@@ -48,20 +46,20 @@ class Punch < ActiveRecord::Base
|
|
48
46
|
def day_combo?
|
49
47
|
timeframe == :day
|
50
48
|
end
|
51
|
-
|
49
|
+
|
52
50
|
def month_combo?
|
53
51
|
timeframe == :month
|
54
52
|
end
|
55
|
-
|
53
|
+
|
56
54
|
def year_combo?
|
57
55
|
timeframe == :year
|
58
56
|
end
|
59
|
-
|
57
|
+
|
60
58
|
def find_combo_for(timeframe)
|
61
59
|
punches = punchable.punches.by_timeframe(timeframe, average_time)
|
62
60
|
punches.combos.first || punches.first
|
63
61
|
end
|
64
|
-
|
62
|
+
|
65
63
|
def combine_with(combo)
|
66
64
|
if combo != self
|
67
65
|
combo.starts_at = starts_at if starts_at < combo.starts_at
|
@@ -72,19 +70,19 @@ class Punch < ActiveRecord::Base
|
|
72
70
|
end
|
73
71
|
combo
|
74
72
|
end
|
75
|
-
|
73
|
+
|
76
74
|
def combine_by_day
|
77
75
|
unless day_combo? || month_combo? || year_combo?
|
78
76
|
combine_with find_combo_for(:day)
|
79
77
|
end
|
80
78
|
end
|
81
|
-
|
79
|
+
|
82
80
|
def combine_by_month
|
83
81
|
unless month_combo? || year_combo?
|
84
82
|
combine_with find_combo_for(:month)
|
85
83
|
end
|
86
84
|
end
|
87
|
-
|
85
|
+
|
88
86
|
def combine_by_year
|
89
87
|
unless year_combo?
|
90
88
|
combine_with find_combo_for(:year)
|
@@ -100,11 +98,11 @@ class Punch < ActiveRecord::Base
|
|
100
98
|
|
101
99
|
return 0 if sums.empty? # catch divide by zero
|
102
100
|
|
103
|
-
sums.values.inject(:+).to_f / sums.length
|
101
|
+
sums.values.inject(:+).to_f / sums.length
|
104
102
|
end
|
105
103
|
|
106
104
|
private
|
107
|
-
|
105
|
+
|
108
106
|
def set_defaults
|
109
107
|
if date = (self.starts_at ||= DateTime.now)
|
110
108
|
self.ends_at ||= date
|
data/lib/punching_bag.rb
CHANGED
@@ -2,7 +2,7 @@ module PunchingBag
|
|
2
2
|
require 'punching_bag/engine' if defined?(Rails)
|
3
3
|
require 'punching_bag/acts_as_punchable'
|
4
4
|
require 'voight_kampff'
|
5
|
-
|
5
|
+
|
6
6
|
def self.punch(punchable, request=nil)
|
7
7
|
if request.try(:bot?)
|
8
8
|
false
|
@@ -12,7 +12,7 @@ module PunchingBag
|
|
12
12
|
p.save ? p : false
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def self.average_time(*punches)
|
17
17
|
total_time = 0
|
18
18
|
hits = 0
|
@@ -22,5 +22,4 @@ module PunchingBag
|
|
22
22
|
end
|
23
23
|
Time.zone.at(total_time / hits)
|
24
24
|
end
|
25
|
-
|
26
|
-
end
|
25
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module PunchingBag
|
2
2
|
module ActiveRecord
|
3
|
-
|
3
|
+
|
4
4
|
module ClassMethods
|
5
5
|
|
6
6
|
# Note: this method will only return items if they have 1 or more hits
|
@@ -17,17 +17,17 @@ module PunchingBag
|
|
17
17
|
query.reorder("SUM(punches.hits) #{dir}")
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
module InstanceMethods
|
22
22
|
def hits(since=nil)
|
23
23
|
self.punches.after(since).sum(:hits)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def punch(request=nil)
|
27
27
|
PunchingBag.punch(self, request)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -10,7 +10,7 @@ module ActsAsTaggableOn
|
|
10
10
|
query = query.where('punches.average_time >= ?', since) if since
|
11
11
|
query.map(&:tag)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def hits(since=nil)
|
15
15
|
query = Tagging.scoped.
|
16
16
|
joins('INNER JOIN punches ON (taggings.taggable_id = punches.punchable_id AND taggings.taggable_type = punches.punchable_type)').
|
data/lib/punching_bag/version.rb
CHANGED
metadata
CHANGED
@@ -1,47 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: punching_bag
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 3
|
10
|
-
version: 0.3.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.4
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Adam Crownoble
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: voight_kampff
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 25
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 1
|
32
|
-
- 1
|
18
|
+
- !ruby/object:Gem::Version
|
33
19
|
version: 0.1.1
|
34
20
|
type: :runtime
|
35
|
-
|
36
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.1
|
27
|
+
description: PunchingBag is a hit counting and simple trending engine for Ruby on
|
28
|
+
Rails
|
37
29
|
email: adam@obledesign.com
|
38
30
|
executables: []
|
39
|
-
|
40
31
|
extensions: []
|
41
|
-
|
42
32
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
33
|
+
files:
|
45
34
|
- app/models/punch.rb
|
46
35
|
- lib/punching_bag/version.rb
|
47
36
|
- lib/punching_bag/engine.rb
|
@@ -53,36 +42,25 @@ files:
|
|
53
42
|
- lib/tasks/punching_bag.rake
|
54
43
|
homepage: https://github.com/biola/punching_bag
|
55
44
|
licenses: []
|
56
|
-
|
45
|
+
metadata: {}
|
57
46
|
post_install_message:
|
58
47
|
rdoc_options: []
|
59
|
-
|
60
|
-
require_paths:
|
48
|
+
require_paths:
|
61
49
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
none: false
|
73
|
-
requirements:
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
hash: 3
|
77
|
-
segments:
|
78
|
-
- 0
|
79
|
-
version: "0"
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
80
60
|
requirements: []
|
81
|
-
|
82
61
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
62
|
+
rubygems_version: 2.0.3
|
84
63
|
signing_key:
|
85
|
-
specification_version:
|
64
|
+
specification_version: 4
|
86
65
|
summary: PunchingBag hit conter and trending plugin
|
87
66
|
test_files: []
|
88
|
-
|