Skip to content

Commit fd4368d

Browse files
⚠️ Drop support for Ruby < 2.6 & clarify version policy (stripe#1684)
* update version requirements * linting * Fix linting * add ci comment * remove unused block
1 parent 3919242 commit fd4368d

14 files changed

Lines changed: 121 additions & 139 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ jobs:
4646
runs-on: ubuntu-22.04
4747
strategy:
4848
matrix:
49-
ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, jruby-9.4.0.0, truffleruby-head]
49+
# following https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
50+
ruby-version: [2.6, 2.7, '3.0', 3.1, 3.2, 3.3, 3.4, jruby-9.4.0.0, truffleruby-head]
5051
steps:
5152
- uses: extractions/setup-just@v2
5253
- uses: actions/checkout@v3

.rubocop.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ inherit_from: .rubocop_todo.yml
22

33
AllCops:
44
DisplayCopNames: true
5-
TargetRubyVersion: 2.3
5+
TargetRubyVersion: 2.6
6+
SuggestExtensions: false
67

78
Layout/CaseIndentation:
89
EnforcedStyle: end
@@ -72,14 +73,6 @@ Metrics/MethodLength:
7273
- initialize
7374
- inner_class_types
7475

75-
# TODO(xavdid): remove this once the first `basil` release is out
76-
Naming/MethodName:
77-
# these endpoints are removed soon so we pulled their overrides, meaning their names are wrong
78-
# that won't make it out to users, but it's breaking linting/formatting in the meantime
79-
Exclude:
80-
- "lib/stripe/services/invoice_service.rb"
81-
- "lib/stripe/resources/invoice.rb"
82-
8376
Metrics/ModuleLength:
8477
Enabled: false
8578

@@ -122,6 +115,9 @@ Style/HashTransformKeys:
122115

123116
Style/HashTransformValues:
124117
Enabled: true
118+
Exclude:
119+
# RUN_DEVSDK-1956
120+
- "lib/stripe/api_requestor.rb"
125121

126122
Style/NumericPredicate:
127123
Enabled: false
@@ -266,6 +262,9 @@ Style/MapCompactWithConditionalBlock: # new in 1.30
266262
Enabled: true
267263
Style/MapToHash: # new in 1.24
268264
Enabled: true
265+
Exclude:
266+
# RUN_DEVSDK-1956
267+
- "lib/stripe/api_requestor.rb"
269268
Style/MapToSet: # new in 1.42
270269
Enabled: true
271270
Style/MinMaxComparison: # new in 1.42

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ gem build stripe.gemspec
3737

3838
### Requirements
3939

40-
- Ruby 2.3+.
40+
Per our [Language Version Support Policy](https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy), we currently support **Ruby 2.6+**.
41+
42+
Support for Ruby 2.6 and 2.7 is deprecated and will be removed in upcoming major versions. Read more and see the full schedule in the docs: https://docs.stripe.com/sdks/versioning?server=ruby#stripe-sdk-language-version-support-policy
4143

4244
### Bundler
4345

@@ -55,8 +57,7 @@ gem 'stripe'
5557
## Usage
5658

5759
The library needs to be configured with your account's secret key which is
58-
available in your [Stripe Dashboard][api-keys]. Set `Stripe.api_key` to its
59-
value:
60+
available in your [Stripe Dashboard][api-keys]. Initialize a new client with your API key:
6061

6162
```ruby
6263
require 'stripe'

lib/stripe/api_requestor.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,10 @@ def self.maybe_gc_connection_managers
572572
headers["Content-Type"] = content_type
573573

574574
# `#to_s` any complex objects like files and the like to build output
575-
# that's more condusive to logging.
575+
# that's more conducive to logging.
576576
flattened_params =
577+
# https://go/j/RUN_DEVSDK-1956 - this is probably a bug
578+
# once fixed, you can remove the exclusions referencing this ticket in .rubocop.yml
577579
flattened_params.map { |k, v| [k, v.is_a?(String) ? v : v.to_s] }.to_h
578580

579581
elsif api_mode == :v2

lib/stripe/request_options.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ def self.persistable(req_opts)
132132

133133
# Get options that are copyable from StripeObject to StripeObject
134134
def self.copyable(req_opts)
135-
req_opts.select do |k, _v|
136-
RequestOptions::OPTS_COPYABLE.include?(k)
137-
end
135+
req_opts.slice(*RequestOptions::OPTS_COPYABLE)
138136
end
139137
end
140138
end

lib/stripe/stripe_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def initialize(api_key,
4343
connect_base: connect_base,
4444
meter_events_base: meter_events_base,
4545
client_id: client_id,
46-
}.reject { |_k, v| v.nil? }
46+
}.compact
4747

4848
config = StripeConfiguration.client_init(config_opts)
4949
@requestor = APIRequestor.new(config)

lib/stripe/stripe_configuration.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ def self.client_init(config_opts)
4545
imported_options = USER_CONFIGURABLE_GLOBAL_OPTIONS - StripeClient::CLIENT_OPTIONS
4646
client_config = StripeConfiguration.setup do |instance|
4747
imported_options.each do |key|
48-
begin
49-
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
50-
rescue NotImplementedError => e
51-
# In Ruby <= 2.5, we can't set write_timeout on Net::HTTP, log an error and continue
52-
Util.log_error("Failed to set #{key} on client configuration: #{e}")
53-
end
48+
instance.public_send("#{key}=", global_config.public_send(key)) if global_config.respond_to?(key)
5449
end
5550
end
5651
client_config.reverse_duplicate_merge(config_opts)

lib/stripe/stripe_object.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ def to_hash
202202
value.respond_to?(:to_hash) ? value.to_hash : value
203203
end
204204

205-
@values.each_with_object({}) do |(key, value), acc|
206-
acc[key] = case value
207-
when Array
208-
value.map(&maybe_to_hash)
209-
else
210-
maybe_to_hash.call(value)
211-
end
205+
@values.transform_values do |value|
206+
case value
207+
when Array
208+
value.map(&maybe_to_hash)
209+
else
210+
maybe_to_hash.call(value)
211+
end
212212
end
213213
end
214214

@@ -273,7 +273,7 @@ def serialize_params(options = {})
273273

274274
# a `nil` that makes it out of `#serialize_params_value` signals an empty
275275
# value that we shouldn't appear in the serialized form of the object
276-
update_hash.reject! { |_, v| v.nil? }
276+
update_hash.compact!
277277

278278
update_hash
279279
end

lib/stripe/util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def self.normalize_opts(opts)
328328
def self.valid_variable_name?(key)
329329
return false if key.empty? || key[0] !~ LEGAL_FIRST_CHARACTER
330330

331-
key[1..-1].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
331+
key[1..].chars.all? { |char| char =~ LEGAL_VARIABLE_CHARACTER }
332332
end
333333

334334
def self.check_string_argument!(key)
@@ -428,7 +428,7 @@ def self.level_name(level)
428428
private_class_method :level_name
429429

430430
def self.log_internal(message, data = {}, color:, level:, logger:, out:)
431-
data_str = data.reject { |_k, v| v.nil? }
431+
data_str = data.compact
432432
.map do |(k, v)|
433433
format("%<key>s=%<value>s",
434434
key: colorize(k, color, logger.nil? && !out.nil? && out.isatty),

stripe.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require "stripe/version"
77
Gem::Specification.new do |s|
88
s.name = "stripe"
99
s.version = Stripe::VERSION
10-
s.required_ruby_version = ">= 2.3.0"
10+
s.required_ruby_version = ">= 2.6.0"
1111
s.summary = "Ruby bindings for the Stripe API"
1212
s.description = "Stripe is the easiest way to accept payments online. " \
1313
"See https://stripe.com for details."

0 commit comments

Comments
 (0)