prop 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/prop.rb +8 -8
- data/prop.gemspec +2 -2
- data/test/test_prop.rb +14 -0
- metadata +22 -23
data/lib/prop.rb
CHANGED
@@ -7,7 +7,7 @@ class Object
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Prop
|
10
|
-
VERSION = "0.6.
|
10
|
+
VERSION = "0.6.6"
|
11
11
|
|
12
12
|
class RateLimitExceededError < RuntimeError
|
13
13
|
attr_accessor :handle, :retry_after, :description
|
@@ -54,7 +54,7 @@ class Prop
|
|
54
54
|
|
55
55
|
def throttle!(handle, key = nil, options = {})
|
56
56
|
options = sanitized_prop_options(handle, key, options)
|
57
|
-
cache_key = sanitized_prop_key(key, options
|
57
|
+
cache_key = sanitized_prop_key(handle, key, options)
|
58
58
|
counter = reader.call(cache_key).to_i
|
59
59
|
|
60
60
|
return counter if disabled?
|
@@ -68,21 +68,21 @@ class Prop
|
|
68
68
|
|
69
69
|
def throttled?(handle, key = nil, options = {})
|
70
70
|
options = sanitized_prop_options(handle, key, options)
|
71
|
-
cache_key = sanitized_prop_key(key, options
|
71
|
+
cache_key = sanitized_prop_key(handle, key, options)
|
72
72
|
|
73
73
|
reader.call(cache_key).to_i >= options[:threshold]
|
74
74
|
end
|
75
75
|
|
76
76
|
def reset(handle, key = nil, options = {})
|
77
77
|
options = sanitized_prop_options(handle, key, options)
|
78
|
-
cache_key = sanitized_prop_key(key, options
|
78
|
+
cache_key = sanitized_prop_key(handle, key, options)
|
79
79
|
|
80
80
|
writer.call(cache_key, 0)
|
81
81
|
end
|
82
82
|
|
83
83
|
def query(handle, key = nil, options = {})
|
84
84
|
options = sanitized_prop_options(handle, key, options)
|
85
|
-
cache_key = sanitized_prop_key(key, options
|
85
|
+
cache_key = sanitized_prop_key(handle, key, options)
|
86
86
|
|
87
87
|
reader.call(cache_key).to_i
|
88
88
|
end
|
@@ -91,9 +91,9 @@ class Prop
|
|
91
91
|
private
|
92
92
|
|
93
93
|
# Builds the expiring cache key
|
94
|
-
def sanitized_prop_key(key,
|
95
|
-
window = (Time.now.to_i / interval)
|
96
|
-
cache_key =
|
94
|
+
def sanitized_prop_key(handle, key, options)
|
95
|
+
window = (Time.now.to_i / options[:interval])
|
96
|
+
cache_key = normalize_cache_key([handle, key, window])
|
97
97
|
"prop/#{Digest::MD5.hexdigest(cache_key)}"
|
98
98
|
end
|
99
99
|
|
data/prop.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'prop'
|
16
|
-
s.version = '0.6.
|
17
|
-
s.date = '
|
16
|
+
s.version = '0.6.6'
|
17
|
+
s.date = '2012-03-31'
|
18
18
|
s.rubyforge_project = 'prop'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
data/test/test_prop.rb
CHANGED
@@ -179,5 +179,19 @@ class TestProp < Test::Unit::TestCase
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
context 'different handles with the same interval' do
|
183
|
+
setup do
|
184
|
+
Prop.configure(:api_requests, :threshold => 100, :interval => 30)
|
185
|
+
Prop.configure(:login_attempts, :threshold => 10, :interval => 30)
|
186
|
+
end
|
187
|
+
|
188
|
+
should 'be counted separately' do
|
189
|
+
user_id = 42
|
190
|
+
Prop.throttle!(:api_requests, user_id)
|
191
|
+
assert_equal(1, Prop.count(:api_requests, user_id))
|
192
|
+
assert_equal(0, Prop.count(:login_attempts, user_id))
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
182
196
|
end
|
183
197
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 6
|
10
|
+
version: 0.6.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Morten Primdahl
|
@@ -15,13 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-03-31 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: rake
|
23
|
-
|
24
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
@@ -30,12 +29,12 @@ dependencies:
|
|
30
29
|
segments:
|
31
30
|
- 0
|
32
31
|
version: "0"
|
33
|
-
|
34
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
35
34
|
- !ruby/object:Gem::Dependency
|
36
35
|
name: bundler
|
37
|
-
|
38
|
-
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
38
|
none: false
|
40
39
|
requirements:
|
41
40
|
- - ">="
|
@@ -44,12 +43,12 @@ dependencies:
|
|
44
43
|
segments:
|
45
44
|
- 0
|
46
45
|
version: "0"
|
47
|
-
|
48
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
49
48
|
- !ruby/object:Gem::Dependency
|
50
49
|
name: shoulda
|
51
|
-
|
52
|
-
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
52
|
none: false
|
54
53
|
requirements:
|
55
54
|
- - ">="
|
@@ -58,12 +57,12 @@ dependencies:
|
|
58
57
|
segments:
|
59
58
|
- 0
|
60
59
|
version: "0"
|
61
|
-
|
62
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
63
62
|
- !ruby/object:Gem::Dependency
|
64
63
|
name: mocha
|
65
|
-
|
66
|
-
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
66
|
none: false
|
68
67
|
requirements:
|
69
68
|
- - ">="
|
@@ -72,8 +71,8 @@ dependencies:
|
|
72
71
|
segments:
|
73
72
|
- 0
|
74
73
|
version: "0"
|
75
|
-
|
76
|
-
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
77
76
|
description: Gem for implementing rate limits.
|
78
77
|
email: primdahl@me.com
|
79
78
|
executables: []
|
@@ -92,7 +91,6 @@ files:
|
|
92
91
|
- prop.gemspec
|
93
92
|
- test/helper.rb
|
94
93
|
- test/test_prop.rb
|
95
|
-
has_rdoc: true
|
96
94
|
homepage: http://github.com/morten/prop
|
97
95
|
licenses: []
|
98
96
|
|
@@ -122,9 +120,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
120
|
requirements: []
|
123
121
|
|
124
122
|
rubyforge_project: prop
|
125
|
-
rubygems_version: 1.
|
123
|
+
rubygems_version: 1.8.15
|
126
124
|
signing_key:
|
127
125
|
specification_version: 2
|
128
126
|
summary: Gem for implementing rate limits.
|
129
127
|
test_files:
|
130
128
|
- test/test_prop.rb
|
129
|
+
has_rdoc:
|