fine_tune 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/README.md +1 -0
- data/lib/fine_tune/base.rb +7 -6
- data/lib/fine_tune/strategies/base.rb +2 -1
- data/lib/fine_tune/strategies/leaky_bucket.rb +2 -2
- data/lib/fine_tune/version.rb +1 -1
- metadata +2 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/laknath/fine_tune.svg?branch=master)](https://travis-ci.org/laknath/fine_tune)
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/fine_tune.svg)](https://badge.fury.io/rb/fine_tune)
|
2
3
|
|
3
4
|
# FineTune - a flexible rate limiting/monitoring library
|
4
5
|
|
data/lib/fine_tune/base.rb
CHANGED
@@ -64,7 +64,8 @@ module FineTune
|
|
64
64
|
# # some calculation ...
|
65
65
|
# end
|
66
66
|
|
67
|
-
def throttle(name, id, options)
|
67
|
+
def throttle(name, id, options = {})
|
68
|
+
options[:validate] = true
|
68
69
|
strategy, key, options = current_strategy(name, id, options)
|
69
70
|
count = strategy.increment(key, options)
|
70
71
|
comp = strategy.compare?(count, options)
|
@@ -79,7 +80,7 @@ module FineTune
|
|
79
80
|
#
|
80
81
|
# Attributes and options are same as for +throttle+.
|
81
82
|
|
82
|
-
def throttle!(name, id, options)
|
83
|
+
def throttle!(name, id, options = {})
|
83
84
|
throttle(name, id, options) do |count, comp, key, strategy, opts|
|
84
85
|
yield count, comp, key, strategy, opts if block_given?
|
85
86
|
|
@@ -90,7 +91,7 @@ module FineTune
|
|
90
91
|
# Returns true if current count exceeds the given limits.
|
91
92
|
#
|
92
93
|
# Attributes and options are same as for +throttle+.
|
93
|
-
def rate_exceeded?(name, id, options)
|
94
|
+
def rate_exceeded?(name, id, options = {})
|
94
95
|
strategy, key, options = current_strategy(name, id, options)
|
95
96
|
strategy.compare?(strategy.count(key, options), options) >= 0
|
96
97
|
end
|
@@ -98,7 +99,7 @@ module FineTune
|
|
98
99
|
# Returns the current event count.
|
99
100
|
#
|
100
101
|
# Attributes and options are same as for +throttle+.
|
101
|
-
def count(name, id, options)
|
102
|
+
def count(name, id, options = {})
|
102
103
|
strategy, key, options = current_strategy(name, id, options)
|
103
104
|
strategy.count(key, options)
|
104
105
|
end
|
@@ -106,7 +107,7 @@ module FineTune
|
|
106
107
|
# Resets the counter for the given resource identifer to 0.
|
107
108
|
#
|
108
109
|
# Attributes and options are same as for +throttle+.
|
109
|
-
def reset(name, id, options)
|
110
|
+
def reset(name, id, options = {})
|
110
111
|
strategy, key, options = current_strategy(name, id, options)
|
111
112
|
strategy.reset(key, options)
|
112
113
|
end
|
@@ -143,7 +144,7 @@ module FineTune
|
|
143
144
|
options = (limits[name] || {}).merge(options)
|
144
145
|
strategy = self.class.find_strategy(options[:strategy])
|
145
146
|
|
146
|
-
if strategy.validate?(options)
|
147
|
+
if !options.delete(:validate) || strategy.validate?(options)
|
147
148
|
key = strategy.build_key(name, id, options)
|
148
149
|
end
|
149
150
|
|
@@ -39,8 +39,8 @@ module FineTune
|
|
39
39
|
# * +:average+ - can be used to override default_average ie: 10
|
40
40
|
# * +:window+ - can be used to override default_window ie: 3600 (one hour)
|
41
41
|
def increment(key, options)
|
42
|
-
count =
|
43
|
-
count = [maximum(options), count
|
42
|
+
count = super(key, options)
|
43
|
+
count = [maximum(options), count].min
|
44
44
|
adapter.write(key, {count: count, timestamp: Time.now.to_i})
|
45
45
|
count
|
46
46
|
end
|
data/lib/fine_tune/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fine_tune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-07-
|
12
|
+
date: 2016-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|