rails_throttle 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 492c5d6e293b452d648df87c5324fbc88a4673127b7a023449d2a238e058fcc4
4
- data.tar.gz: 0ce27efa3cacce1d6ef4d2b48c7784a0cde6b8fb5a40612590fdd7854dd6eef9
3
+ metadata.gz: c7003a6480b112a8c0bda90e1e3508295a9ad0846bfab4cbe0088e8a56623622
4
+ data.tar.gz: da9a5134768e3311c56af5c05fa5f48abfcaa357ff057057ee959834ec61a927
5
5
  SHA512:
6
- metadata.gz: ab45d55646fe2e81133db0383e40ca071b0ad49df68d106a283ba49bfdffc179dfbe7a225a2dfadf8129afc351ba8116381c23e4953da9a9c4bad9ec8c859433
7
- data.tar.gz: 5f9d4a40294454bd0377fb13d5af9da328f4b80330cb70d4038cf48d3fb3eaf04d3e583d1a0ee4cc93f777018b333f9f093436693088d664a6e11820a1d31920
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.1.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", limit: 4, period: 2.seconds) # => 1
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.
@@ -1,3 +1,3 @@
1
1
  module RailsThrottle
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.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-27 00:00:00.000000000 Z
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport