better_rate_limit 0.1.5 → 0.1.6

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: 698bf0e0ba70aab7b648cb4e491697a629c7317f56177c2b62577300dfd226f3
4
- data.tar.gz: 49765bc3916fb28fcd06ff924f892d3d90d04156f244b60850bcd1b4539b7110
3
+ metadata.gz: fd081be677a01d7f69d7e6e6ada8a3172d84d6ee74fbf7ccab5d5fbecb89ee58
4
+ data.tar.gz: 2817642bfee1165564273b8b36ae434e02e7135c6e63a887a4c178c4558d3752
5
5
  SHA512:
6
- metadata.gz: cd2d27993d49945a2585b939759f9ac3196562f548f39fa812d12b51405e41e024e6c27eb769930592b570285576655275afb3ab9561685e8ff79cbc67405052
7
- data.tar.gz: 3736574686273346443af48fdbe72af7f2a98bb164e45bc7734683a8b6cdd3d1d2889f1415874a35f5dfbafb1061b6af416ed957de08eda1fc66bd56d6208b9f
6
+ metadata.gz: bdd3fda987a39c8027d47ddec7b6112e089a609aaabd3a924e71a76417619b69284416183d68744ea05fa55b47e1cead0d04cb99ddb33937e6db97f578d784db
7
+ data.tar.gz: 7b03b579af9be74f8669af5531d254580b0f384232dc5cb295f6d4cbcea7ca3525d42ee41105f0c08dd121c6a68d91544e06dd38a7044bd0b4062cc6007077c5
data/README.md CHANGED
@@ -41,6 +41,15 @@ ActiveSupport::Notifications.subscribe /rate_limit/ do |_name, _start, _finish,
41
41
  end
42
42
  ```
43
43
 
44
+ ### Configuration
45
+ You can ignore the throttle by using the following configuration
46
+ ```ruby
47
+ BetterRateLimit.configure do |config|
48
+ config.ignore = true
49
+ end
50
+ ```
51
+ Useful to ignore the throttle on tests.
52
+
44
53
  ## Development
45
54
 
46
55
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,4 +1,21 @@
1
1
  require 'action_controller'
2
+ require 'better_rate_limit/configuration'
3
+
4
+ module BetterRateLimit
5
+ class << self
6
+ def configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def configure
11
+ yield configuration
12
+ end
13
+
14
+ def reset_configuration
15
+ @configuration = Configuration.new
16
+ end
17
+ end
18
+ end
2
19
 
3
20
  module ActionController
4
21
  autoload :BetterRateLimit, 'action_controller/better_rate_limit'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BetterRateLimit
4
+ class Configuration
5
+ attr_accessor :ignore
6
+
7
+ def initialize
8
+ @ignore = false
9
+ end
10
+ end
11
+ end
@@ -10,6 +10,8 @@ module BetterRateLimit
10
10
 
11
11
  class << self
12
12
  def throttle(key, limit:, time_window:)
13
+ return true if BetterRateLimit.configuration.ignore
14
+
13
15
  now = Time.now.utc
14
16
  timestamps_count = redis_client.llen key
15
17
 
@@ -1,3 +1,3 @@
1
1
  module BetterRateLimit
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_rate_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Fonseca
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-05-28 00:00:00.000000000 Z
12
+ date: 2021-07-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -58,6 +58,7 @@ files:
58
58
  - bin/setup
59
59
  - lib/action_controller/better_rate_limit.rb
60
60
  - lib/better_rate_limit.rb
61
+ - lib/better_rate_limit/configuration.rb
61
62
  - lib/better_rate_limit/limit.rb
62
63
  - lib/better_rate_limit/redis_connection.rb
63
64
  - lib/better_rate_limit/throttle.rb
@@ -83,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
84
  - !ruby/object:Gem::Version
84
85
  version: '0'
85
86
  requirements: []
86
- rubygems_version: 3.0.8
87
+ rubygems_version: 3.1.4
87
88
  signing_key:
88
89
  specification_version: 4
89
90
  summary: Rate limit requests