ruby-limiter 2.2.2 → 2.3.1
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/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +60 -0
- data/.github/workflows/cla.yml +23 -0
- data/.github/workflows/release.yml +30 -0
- data/.gitignore +0 -1
- data/.rubocop.yml +11 -3
- data/.ruby-version +1 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +71 -0
- data/README.md +41 -7
- data/Rakefile +1 -1
- data/bin/console +3 -3
- data/bin/rake +4 -2
- data/bin/rubocop +27 -0
- data/dev.yml +2 -1
- data/lib/limiter/clock.rb +2 -2
- data/lib/limiter/mixin.rb +5 -1
- data/lib/limiter/rate_queue.rb +27 -6
- data/lib/limiter/version.rb +1 -1
- data/lib/limiter.rb +4 -4
- data/lib/ruby-limiter.rb +3 -1
- data/limiter.gemspec +23 -19
- metadata +75 -17
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3fa5f9a22fef901283796de71c5f8f9f2e3c15a0ec53437df63a8fd68ab6d68d
|
|
4
|
+
data.tar.gz: 0fb719626ac5314d31d195d0f5058bdb9830355a25648fcb45bed3317e6c2c39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: da3c41e851f8d076dbbae9cfdc6679c9c439091f83b84a15488c1a62d77e0f683a337acfb31b5dad4bc458cbe967d1929a1a50c3b7cd177ccdb1b12b80281335
|
|
7
|
+
data.tar.gz: 867e83f64c51472488d584b7eb751b2c8b9836ff8b771f29718d0a55023b95166dde55fe08de217f456030059e279551340c870eceb4ffef0cd5b5f033e7e2f8
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
registries:
|
|
3
|
+
github-com:
|
|
4
|
+
type: git
|
|
5
|
+
url: https://github.com
|
|
6
|
+
username: ${{secrets.DEPENDENCIES_GITHUB_USER}}
|
|
7
|
+
password: ${{secrets.DEPENDENCIES_GITHUB_TOKEN}}
|
|
8
|
+
updates:
|
|
9
|
+
- package-ecosystem: bundler
|
|
10
|
+
directory: "/"
|
|
11
|
+
schedule:
|
|
12
|
+
interval: daily
|
|
13
|
+
open-pull-requests-limit: 100
|
|
14
|
+
insecure-external-code-execution: allow
|
|
15
|
+
registries: "*"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
2
|
+
# They are provided by a third-party and are governed by
|
|
3
|
+
# separate terms of service, privacy policy, and support
|
|
4
|
+
# documentation.
|
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
7
|
+
|
|
8
|
+
name: CI
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
branches: [ "main" ]
|
|
13
|
+
pull_request:
|
|
14
|
+
branches: [ "main" ]
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
actions: read
|
|
18
|
+
contents: read
|
|
19
|
+
security-events: write
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
rubocop:
|
|
23
|
+
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
strategy:
|
|
26
|
+
fail-fast: false
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v3
|
|
30
|
+
- name: Set up Ruby
|
|
31
|
+
uses: ruby/setup-ruby@v1
|
|
32
|
+
with:
|
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
34
|
+
- name: Rubocop run
|
|
35
|
+
run: |
|
|
36
|
+
bash -c "
|
|
37
|
+
bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
|
|
38
|
+
[[ $? -ne 2 ]]
|
|
39
|
+
"
|
|
40
|
+
- name: Upload Sarif output
|
|
41
|
+
uses: github/codeql-action/upload-sarif@v2
|
|
42
|
+
with:
|
|
43
|
+
sarif_file: rubocop.sarif
|
|
44
|
+
|
|
45
|
+
tests:
|
|
46
|
+
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
strategy:
|
|
49
|
+
matrix:
|
|
50
|
+
ruby-version: ['3.2', '3.3', '3.4']
|
|
51
|
+
|
|
52
|
+
steps:
|
|
53
|
+
- uses: actions/checkout@v3
|
|
54
|
+
- name: Set up Ruby
|
|
55
|
+
uses: ruby/setup-ruby@v1
|
|
56
|
+
with:
|
|
57
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
58
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
59
|
+
- name: Run tests
|
|
60
|
+
run: bundle exec rake
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# .github/workflows/cla.yml
|
|
2
|
+
name: Contributor License Agreement (CLA)
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
pull_request_target:
|
|
6
|
+
types: [opened, synchronize]
|
|
7
|
+
issue_comment:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
cla:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
if: |
|
|
14
|
+
(github.event.issue.pull_request
|
|
15
|
+
&& !github.event.issue.pull_request.merged_at
|
|
16
|
+
&& contains(github.event.comment.body, 'signed')
|
|
17
|
+
)
|
|
18
|
+
|| (github.event.pull_request && !github.event.pull_request.merged)
|
|
19
|
+
steps:
|
|
20
|
+
- uses: Shopify/shopify-cla-action@v1
|
|
21
|
+
with:
|
|
22
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
cla-token: ${{ secrets.CLA_TOKEN }}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
release:
|
|
9
|
+
if: github.repository == 'Shopify/limiter'
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: write
|
|
14
|
+
id-token: write
|
|
15
|
+
|
|
16
|
+
environment: release
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout repository
|
|
20
|
+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
|
+
with:
|
|
22
|
+
persist-credentials: false
|
|
23
|
+
|
|
24
|
+
- name: Set up Ruby
|
|
25
|
+
uses: ruby/setup-ruby@e81a8fa391b11a595c1b7ed84177cc0fe02faf83 # v1.328.0
|
|
26
|
+
with:
|
|
27
|
+
bundler-cache: true
|
|
28
|
+
|
|
29
|
+
- name: Release gem on RubyGems.org
|
|
30
|
+
uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
-
|
|
1
|
+
inherit_gem:
|
|
2
|
+
rubocop-shopify: rubocop.yml
|
|
3
|
+
|
|
4
|
+
require:
|
|
5
|
+
- rubocop-minitest
|
|
6
|
+
- rubocop-rake
|
|
3
7
|
|
|
4
8
|
AllCops:
|
|
5
|
-
|
|
9
|
+
NewCops: enable
|
|
10
|
+
|
|
11
|
+
Naming/FileName:
|
|
12
|
+
Exclude:
|
|
13
|
+
- 'lib/ruby-limiter.rb'
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.4.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## v2.3.1
|
|
4
|
+
|
|
5
|
+
- balanced mode now keeps calls `interval / size` apart after the queue has been idle; previously an idle interval let `size` calls through at once and the queue kept bursting until reset (#61)
|
|
6
|
+
- balanced ring is built from a single clock read (#62)
|
|
7
|
+
|
|
8
|
+
## v2.3.0
|
|
9
|
+
|
|
10
|
+
- add support for resetting RateQueue
|
|
11
|
+
- add support for resetting mixin-limited method
|
|
12
|
+
|
|
3
13
|
## v2.2.2
|
|
4
14
|
|
|
5
15
|
- security update to rake 13.0.6 [CVE-2020-8130]
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
ruby-limiter (2.3.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
ast (2.4.2)
|
|
10
|
+
code-scanning-rubocop (0.6.1)
|
|
11
|
+
rubocop (~> 1.0)
|
|
12
|
+
json (2.7.1)
|
|
13
|
+
language_server-protocol (3.17.0.3)
|
|
14
|
+
minitest (5.25.5)
|
|
15
|
+
minitest-focus (1.4.0)
|
|
16
|
+
minitest (>= 4, < 6)
|
|
17
|
+
mocha (2.1.0)
|
|
18
|
+
ruby2_keywords (>= 0.0.5)
|
|
19
|
+
parallel (1.24.0)
|
|
20
|
+
parser (3.3.0.5)
|
|
21
|
+
ast (~> 2.4.1)
|
|
22
|
+
racc
|
|
23
|
+
racc (1.7.3)
|
|
24
|
+
rainbow (3.1.1)
|
|
25
|
+
rake (13.3.0)
|
|
26
|
+
regexp_parser (2.9.0)
|
|
27
|
+
rexml (3.2.8)
|
|
28
|
+
strscan (>= 3.0.9)
|
|
29
|
+
rubocop (1.62.1)
|
|
30
|
+
json (~> 2.3)
|
|
31
|
+
language_server-protocol (>= 3.17.0)
|
|
32
|
+
parallel (~> 1.10)
|
|
33
|
+
parser (>= 3.3.0.2)
|
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
36
|
+
rexml (>= 3.2.5, < 4.0)
|
|
37
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
|
38
|
+
ruby-progressbar (~> 1.7)
|
|
39
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
40
|
+
rubocop-ast (1.31.2)
|
|
41
|
+
parser (>= 3.3.0.4)
|
|
42
|
+
rubocop-minitest (0.33.0)
|
|
43
|
+
rubocop (>= 1.39, < 2.0)
|
|
44
|
+
rubocop-rake (0.6.0)
|
|
45
|
+
rubocop (~> 1.0)
|
|
46
|
+
rubocop-shopify (2.15.1)
|
|
47
|
+
rubocop (~> 1.51)
|
|
48
|
+
ruby-progressbar (1.13.0)
|
|
49
|
+
ruby2_keywords (0.0.5)
|
|
50
|
+
strscan (3.1.0)
|
|
51
|
+
unicode-display_width (2.5.0)
|
|
52
|
+
|
|
53
|
+
PLATFORMS
|
|
54
|
+
arm64-darwin-23
|
|
55
|
+
ruby
|
|
56
|
+
|
|
57
|
+
DEPENDENCIES
|
|
58
|
+
bundler
|
|
59
|
+
code-scanning-rubocop (~> 0.6.1)
|
|
60
|
+
minitest (~> 5.20)
|
|
61
|
+
minitest-focus (~> 1.4)
|
|
62
|
+
mocha (~> 2.1)
|
|
63
|
+
rake (~> 13.0)
|
|
64
|
+
rubocop (~> 1.57)
|
|
65
|
+
rubocop-minitest (~> 0.33.0)
|
|
66
|
+
rubocop-rake (~> 0.6.0)
|
|
67
|
+
rubocop-shopify (~> 2.14)
|
|
68
|
+
ruby-limiter!
|
|
69
|
+
|
|
70
|
+
BUNDLED WITH
|
|
71
|
+
2.6.9
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Limiter [](https://github.com/Shopify/limiter/actions/workflows/ci.yml)
|
|
2
2
|
|
|
3
3
|
This gem implements a simple mechanism to throttle or rate-limit operations in Ruby.
|
|
4
4
|
|
|
@@ -57,8 +57,8 @@ end
|
|
|
57
57
|
|
|
58
58
|
#### Load balancing
|
|
59
59
|
|
|
60
|
-
By default all calls to the `limit_method` will be bursted, e.g. as quick as possible, until the rate is exceeded.
|
|
61
|
-
|
|
60
|
+
By default all calls to the `limit_method` will be bursted, e.g. as quick as possible, until the rate is exceeded. Then
|
|
61
|
+
we wait for the remainder of the interval to continue. To even out the burst, an optional `balanced` parameter can be
|
|
62
62
|
provided to enable interleaving between the method calls, e.g: `interleave = interval / size`.
|
|
63
63
|
|
|
64
64
|
``` ruby
|
|
@@ -75,12 +75,30 @@ For example: with an interval of 60 seconds and a rate of 60:
|
|
|
75
75
|
`balanced: true`
|
|
76
76
|
: We interleave each call with 1 second so we call this method every second.
|
|
77
77
|
|
|
78
|
+
#### Resetting a rate-limited method
|
|
79
|
+
|
|
80
|
+
There are times when it may be necessary to reset the rate limiter for a method, for example during testing.
|
|
81
|
+
|
|
82
|
+
This can be done by calling `reset_method_limit!` on the class, where "method" is replaced with the name of the method
|
|
83
|
+
being limited.
|
|
84
|
+
|
|
85
|
+
Given the example above, the following would reset the rate limit for the `tick` method during test setup:
|
|
86
|
+
|
|
87
|
+
``` ruby
|
|
88
|
+
class WidgetTest < Minitest::Test
|
|
89
|
+
def setup
|
|
90
|
+
Widget.reset_tick_limit!
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
...
|
|
94
|
+
end
|
|
95
|
+
```
|
|
78
96
|
|
|
79
97
|
### Advanced Usage
|
|
80
98
|
|
|
81
99
|
In cases where the mixin is not appropriate the `RateQueue` class can be used directly. As in the mixin examples above,
|
|
82
|
-
the `interval` parameter is optional (and defaults to 1 minute). It is also possible
|
|
83
|
-
|
|
100
|
+
the `interval` parameter is optional (and defaults to 1 minute). It is also possible to provide the block to
|
|
101
|
+
`RateQueue`, which will be executed on each limit hit (useful for metrics).
|
|
84
102
|
|
|
85
103
|
``` ruby
|
|
86
104
|
class Widget
|
|
@@ -99,11 +117,27 @@ class Widget
|
|
|
99
117
|
end
|
|
100
118
|
```
|
|
101
119
|
|
|
120
|
+
#### Resetting a RateQueue
|
|
121
|
+
|
|
122
|
+
In some circumstances it may be desirable to reset a rate queue, for example after invoking an API that resets an
|
|
123
|
+
external rate limit.
|
|
124
|
+
|
|
125
|
+
This can be done by calling `reset` on the queue.
|
|
126
|
+
|
|
127
|
+
``` ruby
|
|
128
|
+
...
|
|
129
|
+
@queue.reset
|
|
130
|
+
...
|
|
131
|
+
```
|
|
132
|
+
|
|
102
133
|
## Development
|
|
103
134
|
|
|
104
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
|
135
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can
|
|
136
|
+
also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
105
137
|
|
|
106
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
|
138
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
|
|
139
|
+
version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
|
|
140
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
107
141
|
|
|
108
142
|
## Contributing
|
|
109
143
|
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
-
require
|
|
5
|
-
require
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "limiter"
|
|
6
6
|
|
|
7
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
@@ -11,5 +11,5 @@ require 'limiter'
|
|
|
11
11
|
# require 'pry'
|
|
12
12
|
# Pry.start
|
|
13
13
|
|
|
14
|
-
require
|
|
14
|
+
require "irb"
|
|
15
15
|
IRB.start(__FILE__)
|
data/bin/rake
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
#
|
|
10
10
|
|
|
11
11
|
require "pathname"
|
|
12
|
-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
|
13
|
-
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
|
13
|
+
"../../Gemfile",
|
|
14
|
+
Pathname.new(__FILE__).realpath,
|
|
15
|
+
)
|
|
14
16
|
|
|
15
17
|
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
18
|
|
data/bin/rubocop
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
|
12
|
+
|
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
|
14
|
+
|
|
15
|
+
if File.file?(bundle_binstub)
|
|
16
|
+
if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
|
|
17
|
+
load(bundle_binstub)
|
|
18
|
+
else
|
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
require "rubygems"
|
|
25
|
+
require "bundler/setup"
|
|
26
|
+
|
|
27
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/dev.yml
CHANGED
data/lib/limiter/clock.rb
CHANGED
data/lib/limiter/mixin.rb
CHANGED
data/lib/limiter/rate_queue.rb
CHANGED
|
@@ -8,10 +8,20 @@ module Limiter
|
|
|
8
8
|
@size = size
|
|
9
9
|
@interval = interval
|
|
10
10
|
|
|
11
|
-
@
|
|
12
|
-
|
|
11
|
+
@balanced = balanced
|
|
12
|
+
|
|
13
13
|
@mutex = Mutex.new
|
|
14
14
|
@blk = blk
|
|
15
|
+
|
|
16
|
+
reset
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def reset
|
|
20
|
+
@mutex.synchronize do
|
|
21
|
+
@ring = @balanced ? balanced_ring : unbalanced_ring
|
|
22
|
+
@head = 0
|
|
23
|
+
@last = nil
|
|
24
|
+
end
|
|
15
25
|
end
|
|
16
26
|
|
|
17
27
|
def shift
|
|
@@ -20,9 +30,9 @@ module Limiter
|
|
|
20
30
|
@mutex.synchronize do
|
|
21
31
|
time = @ring[@head]
|
|
22
32
|
|
|
23
|
-
sleep_until(time
|
|
33
|
+
sleep_until(next_time(time))
|
|
24
34
|
|
|
25
|
-
@ring[@head] = clock.time
|
|
35
|
+
@last = @ring[@head] = clock.time
|
|
26
36
|
@head = (@head + 1) % @size
|
|
27
37
|
end
|
|
28
38
|
|
|
@@ -31,10 +41,18 @@ module Limiter
|
|
|
31
41
|
|
|
32
42
|
private
|
|
33
43
|
|
|
44
|
+
def next_time(time)
|
|
45
|
+
deadline = time + @interval
|
|
46
|
+
return deadline unless @balanced && @last
|
|
47
|
+
|
|
48
|
+
[deadline, @last + gap].max
|
|
49
|
+
end
|
|
50
|
+
|
|
34
51
|
def sleep_until(time)
|
|
35
52
|
interval = time - clock.time
|
|
36
53
|
return unless interval.positive?
|
|
37
|
-
|
|
54
|
+
|
|
55
|
+
@blk&.call
|
|
38
56
|
clock.sleep(interval)
|
|
39
57
|
end
|
|
40
58
|
|
|
@@ -47,7 +65,10 @@ module Limiter
|
|
|
47
65
|
end
|
|
48
66
|
|
|
49
67
|
def balanced_ring
|
|
50
|
-
|
|
68
|
+
start = base_time
|
|
69
|
+
step = gap
|
|
70
|
+
|
|
71
|
+
Array.new(@size) { |i| start + (step * i) }
|
|
51
72
|
end
|
|
52
73
|
|
|
53
74
|
def gap
|
data/lib/limiter/version.rb
CHANGED
data/lib/limiter.rb
CHANGED
data/lib/ruby-limiter.rb
CHANGED
data/limiter.gemspec
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
lib = File.expand_path(
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require
|
|
5
|
+
require "limiter/version"
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name =
|
|
8
|
+
spec.name = "ruby-limiter"
|
|
9
9
|
spec.version = Limiter::VERSION
|
|
10
|
-
spec.authors = [
|
|
11
|
-
spec.email = [
|
|
10
|
+
spec.authors = ["S. Brent Faulkner"]
|
|
11
|
+
spec.email = ["brent.faulkner@shopify.com"]
|
|
12
12
|
|
|
13
|
-
spec.summary =
|
|
14
|
-
spec.homepage =
|
|
15
|
-
spec.license =
|
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
|
13
|
+
spec.summary = "Simple Ruby rate limiting mechanism."
|
|
14
|
+
spec.homepage = "https://github.com/Shopify/limiter"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
|
|
17
17
|
|
|
18
18
|
if spec.respond_to?(:metadata)
|
|
19
|
-
spec.metadata[
|
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
20
20
|
else
|
|
21
21
|
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
spec.files =
|
|
24
|
+
spec.files = %x(git ls-files -z).split("\x0").reject do |f|
|
|
25
25
|
f.match(%r{^(test|spec|features)/})
|
|
26
26
|
end
|
|
27
|
-
spec.bindir =
|
|
27
|
+
spec.bindir = "exe"
|
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
-
spec.require_paths =
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
30
|
|
|
31
|
-
spec.add_development_dependency
|
|
32
|
-
spec.add_development_dependency
|
|
33
|
-
spec.add_development_dependency
|
|
34
|
-
spec.add_development_dependency
|
|
35
|
-
spec.add_development_dependency
|
|
36
|
-
spec.add_development_dependency
|
|
31
|
+
spec.add_development_dependency("bundler")
|
|
32
|
+
spec.add_development_dependency("code-scanning-rubocop", "~> 0.6.1")
|
|
33
|
+
spec.add_development_dependency("minitest", "~> 5.20")
|
|
34
|
+
spec.add_development_dependency("minitest-focus", "~> 1.4")
|
|
35
|
+
spec.add_development_dependency("mocha", "~> 2.1")
|
|
36
|
+
spec.add_development_dependency("rake", "~> 13.0")
|
|
37
|
+
spec.add_development_dependency("rubocop", "~> 1.57")
|
|
38
|
+
spec.add_development_dependency("rubocop-minitest", "~> 0.33.0")
|
|
39
|
+
spec.add_development_dependency("rubocop-rake", "~> 0.6.0")
|
|
40
|
+
spec.add_development_dependency("rubocop-shopify", "~> 2.14")
|
|
37
41
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-limiter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- S. Brent Faulkner
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -24,48 +23,62 @@ dependencies:
|
|
|
24
23
|
- - ">="
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: code-scanning-rubocop
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 0.6.1
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 0.6.1
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: minitest
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
30
43
|
requirements:
|
|
31
44
|
- - "~>"
|
|
32
45
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '5.
|
|
46
|
+
version: '5.20'
|
|
34
47
|
type: :development
|
|
35
48
|
prerelease: false
|
|
36
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
50
|
requirements:
|
|
38
51
|
- - "~>"
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '5.
|
|
53
|
+
version: '5.20'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: minitest-focus
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
44
57
|
requirements:
|
|
45
58
|
- - "~>"
|
|
46
59
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '1.
|
|
60
|
+
version: '1.4'
|
|
48
61
|
type: :development
|
|
49
62
|
prerelease: false
|
|
50
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
64
|
requirements:
|
|
52
65
|
- - "~>"
|
|
53
66
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '1.
|
|
67
|
+
version: '1.4'
|
|
55
68
|
- !ruby/object:Gem::Dependency
|
|
56
69
|
name: mocha
|
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
|
58
71
|
requirements:
|
|
59
72
|
- - "~>"
|
|
60
73
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1
|
|
74
|
+
version: '2.1'
|
|
62
75
|
type: :development
|
|
63
76
|
prerelease: false
|
|
64
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
78
|
requirements:
|
|
66
79
|
- - "~>"
|
|
67
80
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '1
|
|
81
|
+
version: '2.1'
|
|
69
82
|
- !ruby/object:Gem::Dependency
|
|
70
83
|
name: rake
|
|
71
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -86,31 +99,78 @@ dependencies:
|
|
|
86
99
|
requirements:
|
|
87
100
|
- - "~>"
|
|
88
101
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
102
|
+
version: '1.57'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '1.57'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rubocop-minitest
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: 0.33.0
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: 0.33.0
|
|
124
|
+
- !ruby/object:Gem::Dependency
|
|
125
|
+
name: rubocop-rake
|
|
126
|
+
requirement: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: 0.6.0
|
|
131
|
+
type: :development
|
|
132
|
+
prerelease: false
|
|
133
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - "~>"
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 0.6.0
|
|
138
|
+
- !ruby/object:Gem::Dependency
|
|
139
|
+
name: rubocop-shopify
|
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '2.14'
|
|
90
145
|
type: :development
|
|
91
146
|
prerelease: false
|
|
92
147
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
148
|
requirements:
|
|
94
149
|
- - "~>"
|
|
95
150
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
97
|
-
description:
|
|
151
|
+
version: '2.14'
|
|
98
152
|
email:
|
|
99
153
|
- brent.faulkner@shopify.com
|
|
100
154
|
executables: []
|
|
101
155
|
extensions: []
|
|
102
156
|
extra_rdoc_files: []
|
|
103
157
|
files:
|
|
158
|
+
- ".github/dependabot.yml"
|
|
159
|
+
- ".github/workflows/ci.yml"
|
|
160
|
+
- ".github/workflows/cla.yml"
|
|
161
|
+
- ".github/workflows/release.yml"
|
|
104
162
|
- ".gitignore"
|
|
105
163
|
- ".rubocop.yml"
|
|
106
|
-
- ".
|
|
164
|
+
- ".ruby-version"
|
|
107
165
|
- CHANGELOG.md
|
|
108
166
|
- Gemfile
|
|
167
|
+
- Gemfile.lock
|
|
109
168
|
- LICENSE.txt
|
|
110
169
|
- README.md
|
|
111
170
|
- Rakefile
|
|
112
171
|
- bin/console
|
|
113
172
|
- bin/rake
|
|
173
|
+
- bin/rubocop
|
|
114
174
|
- bin/setup
|
|
115
175
|
- dev.yml
|
|
116
176
|
- lib/limiter.rb
|
|
@@ -125,7 +185,6 @@ licenses:
|
|
|
125
185
|
- MIT
|
|
126
186
|
metadata:
|
|
127
187
|
allowed_push_host: https://rubygems.org
|
|
128
|
-
post_install_message:
|
|
129
188
|
rdoc_options: []
|
|
130
189
|
require_paths:
|
|
131
190
|
- lib
|
|
@@ -133,15 +192,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
133
192
|
requirements:
|
|
134
193
|
- - ">="
|
|
135
194
|
- !ruby/object:Gem::Version
|
|
136
|
-
version:
|
|
195
|
+
version: 3.0.0
|
|
137
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
197
|
requirements:
|
|
139
198
|
- - ">="
|
|
140
199
|
- !ruby/object:Gem::Version
|
|
141
200
|
version: '0'
|
|
142
201
|
requirements: []
|
|
143
|
-
rubygems_version: 3.
|
|
144
|
-
signing_key:
|
|
202
|
+
rubygems_version: 3.6.7
|
|
145
203
|
specification_version: 4
|
|
146
204
|
summary: Simple Ruby rate limiting mechanism.
|
|
147
205
|
test_files: []
|