graph_attack 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5c8d6555e219c82d4a4120f699037145c83a8c6ab5d890aa0f7a75f9560db2c
4
- data.tar.gz: da27f205db905e6a6b3c05dd34b50d4057908372c86bae9b53b8f7cb8ef86e09
3
+ metadata.gz: 14073662874173af1e66adb16931c4e8817461c3f36a0ea341d75dbbafb39b1b
4
+ data.tar.gz: 58f889613e4ea79ce99b19b788ca837527192c85b0b212a77ce84b2355938720
5
5
  SHA512:
6
- metadata.gz: 81506f5a365831038e0fff051d7ef707e4903c561bc8cbbe7148a2ff79daef43ec98e26699331163a42e07328dcd2b08797682155d91b78b54f145809d080dd6
7
- data.tar.gz: 964047fc9a4e4516bdb1d6c0ae899e7fdc484c44c83268e9e7dd6fc13ffb563bdba43a4ba6b3a1cecf8ed538c61ec1804eac64fac7418d1094280280d87aeff1
6
+ metadata.gz: 1e9652eb2b3ec822942e58ba9d351fabc5a913ee8c7d1b06cef5a5574b85aa40e9c8140618aedd8ca1f4a30cf2559a9426762e39e2af8918e6e9b1806bdd8101
7
+ data.tar.gz: f0488943c372fa9bf2d0c48dae7d942b17cafe24ff3a81121fc97e0bd75ffe5d222bf527477d5279e4bcb04e906f327ea1baa2ccefafd9b99cfc11ee57100f83
@@ -0,0 +1,39 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ name: on ruby ${{matrix.ruby}}
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: ['3.0', '3.1', '3.2', '3.3', '3.4', head]
14
+
15
+ services:
16
+ redis:
17
+ image: redis
18
+ options: >-
19
+ --health-cmd "redis-cli ping"
20
+ --health-interval 10s
21
+ --health-timeout 5s
22
+ --health-retries 5
23
+ ports:
24
+ - 6379:6379
25
+
26
+ steps:
27
+ - name: Checkout repository
28
+ uses: actions/checkout@v3
29
+
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{matrix.ruby}}
34
+
35
+ - name: Install dependencies
36
+ run: bundle install --jobs 4 --retry 3
37
+
38
+ - name: RSpec
39
+ run: bin/rspec
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-rspec
3
3
  - rubocop-rake
4
4
 
@@ -6,6 +6,10 @@ AllCops:
6
6
  TargetRubyVersion: 2.7
7
7
  DisplayCopNames: true
8
8
  NewCops: enable
9
+ Exclude:
10
+ - bin/rake
11
+ - bin/rspec
12
+ - bin/rubocop
9
13
 
10
14
  # Do not sort gems in Gemfile, since we are grouping them by functionality.
11
15
  Bundler/OrderedGems:
@@ -37,9 +41,6 @@ Metrics/MethodLength:
37
41
  # Limit line length.
38
42
  Layout/LineLength:
39
43
  Max: 80
40
- Exclude:
41
- - bin/rake
42
- - bin/rubocop
43
44
 
44
45
  # Allow ASCII comments (e.g "…").
45
46
  Style/AsciiComments:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.5
1
+ 3.4.2
data/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  unreleased
2
2
  ----------
3
3
 
4
+ v2.4.0
5
+ ------
6
+
7
+ Feature:
8
+ - Accept ConnectionPool instances as a Redis client.
9
+
10
+ Support:
11
+ - Drop Ruby 2.7 support.
12
+
13
+ v2.3.1
14
+ ------
15
+
16
+ Fix:
17
+ - Relax Ruby version constraint to allow Ruby 3.2.
18
+
4
19
  v2.3.0
5
20
  ------
6
21
 
@@ -22,6 +37,12 @@ v2.2.0
22
37
  Feature:
23
38
  - Skip throttling when rate limited field is nil (#19)
24
39
 
40
+ ⚠️ Possibly breaking change:
41
+ - If your app relied on `Redis.current`, please provide a `redis_client` option
42
+ explicitly, since
43
+ [`Redis.current` is deprecated](https://github.com/redis/redis-rb/commit/9745e22db65ac294be51ed393b584c0f8b72ae98)
44
+ and will be removed in Redis 5.
45
+
25
46
  v2.1.0
26
47
  ------
27
48
 
data/Gemfile CHANGED
@@ -6,3 +6,21 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in graph_attack.gemspec
8
8
  gemspec
9
+
10
+ # Development tasks runner.
11
+ gem 'rake'
12
+
13
+ # Testing framework.
14
+ gem 'rspec'
15
+
16
+ # CircleCI dependency to store spec results.
17
+ gem 'rspec_junit_formatter'
18
+
19
+ # Ruby code linter.
20
+ gem 'rubocop'
21
+
22
+ # RSpec extension for RuboCop.
23
+ gem 'rubocop-rspec'
24
+
25
+ # Rake extension for RuboCop
26
+ gem 'rubocop-rake'
data/README.md CHANGED
@@ -153,3 +153,7 @@ file for details.
153
153
 
154
154
  Hat tip to [Rack::Attack](https://github.com/kickstarter/rack-attack) for the
155
155
  the name.
156
+
157
+ Sponsored by [Cults](https://cults3d.com).
158
+
159
+ ![Cults. Logo](https://github.com/user-attachments/assets/3a51b90d-1033-4df5-a903-03668fc4b966)
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/graph_attack.gemspec CHANGED
@@ -23,32 +23,11 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.required_ruby_version = ['>= 2.5.7', '< 3.2']
26
+ spec.required_ruby_version = '>= 2.5.7'
27
27
 
28
28
  # This gem is an analyser for the GraphQL ruby gem.
29
29
  spec.add_dependency 'graphql', '>= 1.7.9'
30
30
 
31
31
  # A Redis-backed rate limiter.
32
32
  spec.add_dependency 'ratelimit', '>= 1.0.4'
33
-
34
- # Loads local dependencies.
35
- spec.add_development_dependency 'bundler', '~> 2.0'
36
-
37
- # Development tasks runner.
38
- spec.add_development_dependency 'rake', '~> 13.0'
39
-
40
- # Testing framework.
41
- spec.add_development_dependency 'rspec', '~> 3.0'
42
-
43
- # CircleCI dependency to store spec results.
44
- spec.add_development_dependency 'rspec_junit_formatter', '~> 0.3'
45
-
46
- # Ruby code linter.
47
- spec.add_development_dependency 'rubocop', '~> 1.33.0'
48
-
49
- # RSpec extension for RuboCop.
50
- spec.add_development_dependency 'rubocop-rspec', '~> 2.12.1'
51
-
52
- # Rake extension for RuboCop
53
- spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
54
33
  end
@@ -25,10 +25,11 @@ module GraphAttack
25
25
  end
26
26
 
27
27
  def calls_exceeded_on_query?(rate_limited_field)
28
- rate_limit = Ratelimit.new(rate_limited_field, redis: redis_client)
29
- rate_limit.add(key)
30
-
31
- rate_limit.exceeded?(key, threshold: threshold, interval: interval)
28
+ with_redis_client do |redis_client|
29
+ rate_limit = Ratelimit.new(rate_limited_field, redis: redis_client)
30
+ rate_limit.add(key)
31
+ rate_limit.exceeded?(key, threshold: threshold, interval: interval)
32
+ end
32
33
  end
33
34
 
34
35
  def threshold
@@ -49,8 +50,13 @@ module GraphAttack
49
50
  )
50
51
  end
51
52
 
52
- def redis_client
53
- options[:redis_client] || GraphAttack.configuration.redis_client
53
+ def with_redis_client(&block)
54
+ client = options[:redis_client] || GraphAttack.configuration.redis_client
55
+ if client.respond_to?(:then)
56
+ client.then(&block)
57
+ else
58
+ block.call(client)
59
+ end
54
60
  end
55
61
 
56
62
  def on
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphAttack
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graph_attack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fanny Cheung
8
8
  - Sunny Ripert
9
- autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2023-02-03 00:00:00.000000000 Z
11
+ date: 2025-03-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: graphql
@@ -39,104 +38,6 @@ dependencies:
39
38
  - - ">="
40
39
  - !ruby/object:Gem::Version
41
40
  version: 1.0.4
42
- - !ruby/object:Gem::Dependency
43
- name: bundler
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '2.0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '2.0'
56
- - !ruby/object:Gem::Dependency
57
- name: rake
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '13.0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '13.0'
70
- - !ruby/object:Gem::Dependency
71
- name: rspec
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - "~>"
75
- - !ruby/object:Gem::Version
76
- version: '3.0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '3.0'
84
- - !ruby/object:Gem::Dependency
85
- name: rspec_junit_formatter
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '0.3'
91
- type: :development
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '0.3'
98
- - !ruby/object:Gem::Dependency
99
- name: rubocop
100
- requirement: !ruby/object:Gem::Requirement
101
- requirements:
102
- - - "~>"
103
- - !ruby/object:Gem::Version
104
- version: 1.33.0
105
- type: :development
106
- prerelease: false
107
- version_requirements: !ruby/object:Gem::Requirement
108
- requirements:
109
- - - "~>"
110
- - !ruby/object:Gem::Version
111
- version: 1.33.0
112
- - !ruby/object:Gem::Dependency
113
- name: rubocop-rspec
114
- requirement: !ruby/object:Gem::Requirement
115
- requirements:
116
- - - "~>"
117
- - !ruby/object:Gem::Version
118
- version: 2.12.1
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- requirements:
123
- - - "~>"
124
- - !ruby/object:Gem::Version
125
- version: 2.12.1
126
- - !ruby/object:Gem::Dependency
127
- name: rubocop-rake
128
- requirement: !ruby/object:Gem::Requirement
129
- requirements:
130
- - - "~>"
131
- - !ruby/object:Gem::Version
132
- version: 0.6.0
133
- type: :development
134
- prerelease: false
135
- version_requirements: !ruby/object:Gem::Requirement
136
- requirements:
137
- - - "~>"
138
- - !ruby/object:Gem::Version
139
- version: 0.6.0
140
41
  description: GraphQL analyser for blocking & throttling
141
42
  email:
142
43
  - fanny@ynote.hk
@@ -147,6 +48,7 @@ extra_rdoc_files: []
147
48
  files:
148
49
  - ".circleci/config.yml"
149
50
  - ".github/dependabot.yml"
51
+ - ".github/workflows/test.yml"
150
52
  - ".gitignore"
151
53
  - ".rspec"
152
54
  - ".rubocop.yml"
@@ -160,6 +62,7 @@ files:
160
62
  - Rakefile
161
63
  - bin/console
162
64
  - bin/rake
65
+ - bin/rspec
163
66
  - bin/rubocop
164
67
  - bin/setup
165
68
  - graph_attack.gemspec
@@ -173,7 +76,6 @@ homepage: https://github.com/sunny/graph_attack
173
76
  licenses: []
174
77
  metadata:
175
78
  rubygems_mfa_required: 'true'
176
- post_install_message:
177
79
  rdoc_options: []
178
80
  require_paths:
179
81
  - lib
@@ -182,17 +84,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
84
  - - ">="
183
85
  - !ruby/object:Gem::Version
184
86
  version: 2.5.7
185
- - - "<"
186
- - !ruby/object:Gem::Version
187
- version: '3.2'
188
87
  required_rubygems_version: !ruby/object:Gem::Requirement
189
88
  requirements:
190
89
  - - ">="
191
90
  - !ruby/object:Gem::Version
192
91
  version: '0'
193
92
  requirements: []
194
- rubygems_version: 3.1.6
195
- signing_key:
93
+ rubygems_version: 3.6.2
196
94
  specification_version: 4
197
95
  summary: GraphQL analyser for blocking & throttling
198
96
  test_files: []