prop 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/prop.rb +13 -0
- data/prop.gemspec +1 -1
- data/test/test_prop.rb +18 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.1
|
data/lib/prop.rb
CHANGED
@@ -37,11 +37,24 @@ class Prop
|
|
37
37
|
self.handles[handle] = defaults
|
38
38
|
end
|
39
39
|
|
40
|
+
def disabled(&block)
|
41
|
+
@disabled = true
|
42
|
+
yield
|
43
|
+
ensure
|
44
|
+
@disabled = false
|
45
|
+
end
|
46
|
+
|
47
|
+
def disabled?
|
48
|
+
!!@disabled
|
49
|
+
end
|
50
|
+
|
40
51
|
def throttle!(handle, key = nil, options = {})
|
41
52
|
options = sanitized_prop_options(handle, key, options)
|
42
53
|
cache_key = sanitized_prop_key(key, options[:interval])
|
43
54
|
counter = reader.call(cache_key).to_i
|
44
55
|
|
56
|
+
return counter if disabled?
|
57
|
+
|
45
58
|
if counter >= options[:threshold]
|
46
59
|
raise Prop::RateLimitExceededError.create(handle, normalize_cache_key(key), options[:threshold])
|
47
60
|
else
|
data/prop.gemspec
CHANGED
data/test/test_prop.rb
CHANGED
@@ -44,6 +44,24 @@ class TestProp < Test::Unit::TestCase
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
context "#disable" do
|
48
|
+
setup do
|
49
|
+
Prop.configure :hello, :threshold => 10, :interval => 10
|
50
|
+
end
|
51
|
+
|
52
|
+
should "not increase the throttle" do
|
53
|
+
assert_equal 1, Prop.throttle!(:hello)
|
54
|
+
assert_equal 2, Prop.throttle!(:hello)
|
55
|
+
Prop.disabled do
|
56
|
+
assert_equal 2, Prop.throttle!(:hello)
|
57
|
+
assert_equal 2, Prop.throttle!(:hello)
|
58
|
+
assert Prop.disabled?
|
59
|
+
end
|
60
|
+
assert !Prop.disabled?
|
61
|
+
assert_equal 3, Prop.throttle!(:hello)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
47
65
|
context "#reset" do
|
48
66
|
setup do
|
49
67
|
Prop.configure :hello, :threshold => 10, :interval => 10
|
metadata
CHANGED