prop 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/lib/prop.rb +13 -0
  3. data/prop.gemspec +1 -1
  4. data/test/test_prop.rb +18 -0
  5. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{prop}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Morten Primdahl"]
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
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Morten Primdahl