rails_throttle 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/rails_throttle/throttle.rb +7 -2
- data/lib/rails_throttle/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7003a6480b112a8c0bda90e1e3508295a9ad0846bfab4cbe0088e8a56623622
|
4
|
+
data.tar.gz: da9a5134768e3311c56af5c05fa5f48abfcaa357ff057057ee959834ec61a927
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa066f7ae4897aceba8afeaefaaf0b5376fee2e524b99b5f934ff9ae92a236a68d5b6b12d24264b539d2aa89a13d99c5395f3f608f54d2d3b35508eea8052efd
|
7
|
+
data.tar.gz: b1b88b6c7603310456cfacf016501f298adfb2311fcbd65ad5966e109badd21c9df85de158d8172a863eaf8b26ad67ea28a629d7e29086a139ef5374d69f4687
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ RailsThrottle is a simple library used to throttle code in your Rails applicatio
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "rails_throttle", "~> 0.
|
10
|
+
gem "rails_throttle", "~> 0.2.0"
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -33,7 +33,7 @@ Or install it yourself as:
|
|
33
33
|
```ruby
|
34
34
|
RailsThrottle::Throttle.increment("foo", limit: 4, period: 2.seconds) # => 1
|
35
35
|
RailsThrottle::Throttle.increment("foo", limit: 4, period: 2.seconds) # => 2
|
36
|
-
RailsThrottle::Throttle.decrement("foo",
|
36
|
+
RailsThrottle::Throttle.decrement("foo", period: 2.seconds) # => 1
|
37
37
|
RailsThrottle::Throttle.reset("foo")
|
38
38
|
RailsThrottle::Throttle.increment("foo", limit: 4, period: 2.seconds, increment: 4) # => 4
|
39
39
|
RailsThrottle::Throttle.increment("foo", limit: 4, period: 2.seconds) # => RailsThrottle::ThrottleError
|
@@ -24,7 +24,7 @@ module RailsThrottle
|
|
24
24
|
raise "Must specify :limit in the parameters" if limit.nil?
|
25
25
|
raise "Must specify :period in the parameters" if period.nil?
|
26
26
|
|
27
|
-
value = RailsThrottle.backend.increment(key, increment)
|
27
|
+
value = RailsThrottle.backend.increment(key, increment, expires_in: period)
|
28
28
|
|
29
29
|
if value.nil?
|
30
30
|
RailsThrottle.backend.write(key, increment, expires_in: period)
|
@@ -52,13 +52,18 @@ module RailsThrottle
|
|
52
52
|
# @param [String] key The key that uniquely identifies this throttle operation.
|
53
53
|
# @param [Hash] options The options to this increment.
|
54
54
|
# @option options [Integer] :decrement The amount to decrement the counter by, defaults to 1 if not provided.
|
55
|
+
# @option options [Integer] :period The period of time (in seconds) which this throttle applies, the throttle will
|
56
|
+
# expire after this number of seconds.
|
55
57
|
# @return [Integer] The current value of the throttle counter.
|
56
58
|
def self.decrement(key, options = {})
|
57
59
|
raise "Key cannot be blank." if key.blank?
|
58
60
|
|
59
61
|
decrement = options[:decrement] || 1
|
62
|
+
period = options[:period]
|
63
|
+
|
64
|
+
raise "Must specify :period in the parameters" if period.nil?
|
60
65
|
|
61
|
-
RailsThrottle.backend.decrement(key, decrement)
|
66
|
+
RailsThrottle.backend.decrement(key, decrement, expires_in: period)
|
62
67
|
end
|
63
68
|
|
64
69
|
# Returns true if the key is throttled, false otherwise.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_throttle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Zhu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04
|
11
|
+
date: 2019-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|