ruby3-backward-compatibility 1.2.0 → 1.4.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: b9eab8bda5ea5cf123ec7370aae33a25c1e6d3fe16976a778152d3fce153931c
4
- data.tar.gz: 550c09a1aa034b4899f4e21d69b7a2949ec16c15bce430e6a23acf72eb91ad37
3
+ metadata.gz: '09b06d532203cd4e5f4f81dbf7b664fafc62b02700594adc99f6dce8d4fe9449'
4
+ data.tar.gz: f691d1e175588417c95978937bf16d7f8bd2ab42ddfa7b9a14ed5b7ad270e1e9
5
5
  SHA512:
6
- metadata.gz: 645183527ce9549cebfe84924fcff6d8864088a1ef442fb797f6cc1225f2348aba11c170edb58d7633b396a89d5bb327c2863789bb4b4d893e8c15aaad5900b0
7
- data.tar.gz: 6e6382750d9f27dda6195b5cc637bb2dae6b57dfd46ab7afa67dcd0992709017a05771d376f0064b5298db7157ae3cdd8ba1b43ac404df5df6491bafc13ac12b
6
+ metadata.gz: d8863c4305734ac08069902668e536cf165e2e2bbd9dad261ebbc3cdad46d1d73cb366d1e8452578efd82b32efd6e645d5f46dff5f466500f9ac58747cbeaa7f
7
+ data.tar.gz: 614dbb8dedf50e9999e930576c2874bf11d5691bab6ca50fa63bbf83843f6ca11609b646dd34190242a52294bf4b59b2807faf2e4c378d6fc3729a4f46229cea
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2024-05-02
4
+
5
+ - Ruby 3.2+: Add back `Object#=~`
6
+
7
+ ## [1.3.0] - 2024-04-16
8
+
9
+ - Ruby 3.2+: Add back third argument to Regexp.new, to allow passing "n" to set `Regexp::NOENCODING`.
10
+
3
11
  ## [1.2.0] - 2024-04-10
4
12
 
5
13
  - First release with dedicated suport to Ruby 3.3.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby3-backward-compatibility (1.2.0)
4
+ ruby3-backward-compatibility (1.4.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -136,12 +136,25 @@ require 'ruby3_backward_compatibility/compatibility/i18n'
136
136
 
137
137
  The methods `Object#taint` and `Object#untaint` were no-ops for a while but started to raise deprecation warnings.
138
138
 
139
- To add them back as no-ops, use
139
+ The method `Object#=~` always returned `nil` if called on anything else than a String. It was removed in Ruby 3.2.
140
+
141
+ To add back `Object#taint` and `Object#untaint` as no-ops and `Object#=~` on arbitrary receivers, use
140
142
 
141
143
  ```
142
144
  require 'ruby3_backward_compatibility/compatibility/object'
143
145
  ```
144
146
 
147
+ ### Regexp (Ruby 3.2+)
148
+
149
+ It was possible to instantiate a Regexp with `Regexp.new('foo', Regexp::IGNORECASE, 'n')`. The last argument used to indicate the encoding in Ruby 1.8. Up to Ruby 3.2 an argument of "n" or "N" indicated a regexp that ignores encoding (same as the Regexp::NOENCODING flag).
150
+
151
+ In Ruby 3 this raises an `ArgumentError`.
152
+
153
+ To bring back the old behavior, use
154
+
155
+ ```
156
+ require 'ruby3_backward_compatibility/compatibility/regexp'
157
+ ```
145
158
 
146
159
  ### YAML (Psych)
147
160
 
@@ -7,5 +7,6 @@ require 'ruby3_backward_compatibility/compatibility/fixnum'
7
7
  require 'ruby3_backward_compatibility/compatibility/i18n' if defined?(I18n)
8
8
  require 'ruby3_backward_compatibility/compatibility/object'
9
9
  require 'ruby3_backward_compatibility/compatibility/psych' if defined?(Psych)
10
+ require 'ruby3_backward_compatibility/compatibility/regexp'
10
11
  require 'ruby3_backward_compatibility/compatibility/string'
11
12
  require 'ruby3_backward_compatibility/compatibility/uri' if defined?(URI)
@@ -8,6 +8,14 @@ module Ruby3BackwardCompatibility
8
8
  def untaint
9
9
  self
10
10
  end
11
+
12
+ # Make the match operator work on arbitrary receivers again.
13
+ def =~(regexp)
14
+ if Warning[:deprecated]
15
+ Warning.warn("deprecated Object#=~ is called on #{self.class}; it always returns nil")
16
+ end
17
+ nil
18
+ end
11
19
  end
12
20
  end
13
21
 
@@ -0,0 +1,51 @@
1
+ if RUBY_VERSION >= '3.2'
2
+ # on 3.2 exactly, we get deprecation errors
3
+ # however, this is somewhat hard to fix, since 3.2 added some different ways to pass "options" that we do not want to rebuild
4
+
5
+ module Ruby3BackwardCompatibility
6
+ module RegexpCompatibility
7
+ LEGITIMATE_FLAGS = /\A[mix]+\z/
8
+
9
+ def self.prepended(by)
10
+ by.singleton_class.prepend ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ def new(regexp_or_string, options = NOT_GIVEN, n_flag = NOT_GIVEN, **kwargs)
15
+ if options == NOT_GIVEN
16
+ super(regexp_or_string, **kwargs)
17
+ elsif n_flag == 'n' || n_flag == 'N'
18
+ unless options.is_a?(Integer)
19
+ if RUBY_VERSION < '3.3' && options.is_a?(String) && options =~ LEGITIMATE_FLAGS
20
+ # on Ruby 3.2 we can legitimately have options "mix" treated as flags, so parse them
21
+ # on Ruby 3.3 this would never have been legitimate, since a third argument would not have been allowed
22
+ new_options = 0
23
+ new_options |= Regexp::MULTILINE if options.include?('m')
24
+ new_options |= Regexp::IGNORECASE if options.include?('i')
25
+ new_options |= Regexp::EXTENDED if options.include?('x')
26
+ options = new_options
27
+ else
28
+ # on all other Ruby, truish is IGNORECASE
29
+ options = options ? Regexp::IGNORECASE : 0
30
+ end
31
+ end
32
+ super(regexp_or_string, options | Regexp::NOENCODING, **kwargs)
33
+ elsif options.is_a?(String)
34
+ if options =~ LEGITIMATE_FLAGS && n_flag == NOT_GIVEN
35
+ # this (like any trueish value) would have been "ignore case" in Ruby < 3.2, but now is not
36
+ # we have to assume this is Ruby 3.2 syntax
37
+ super(regexp_or_string, options, **kwargs)
38
+ else
39
+ # this crashes on Ruby 3.2, so assume it is < 3.2 syntax
40
+ super(regexp_or_string, true, **kwargs)
41
+ end
42
+ else
43
+ super(regexp_or_string, options, **kwargs)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Regexp.prepend Ruby3BackwardCompatibility::RegexpCompatibility
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruby3BackwardCompatibility
4
- VERSION = '1.2.0'
4
+ VERSION = '1.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby3-backward-compatibility
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-10 00:00:00.000000000 Z
11
+ date: 2024-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -52,6 +52,7 @@ files:
52
52
  - lib/ruby3_backward_compatibility/compatibility/i18n.rb
53
53
  - lib/ruby3_backward_compatibility/compatibility/object.rb
54
54
  - lib/ruby3_backward_compatibility/compatibility/psych.rb
55
+ - lib/ruby3_backward_compatibility/compatibility/regexp.rb
55
56
  - lib/ruby3_backward_compatibility/compatibility/string.rb
56
57
  - lib/ruby3_backward_compatibility/compatibility/uri.rb
57
58
  - lib/ruby3_backward_compatibility/version.rb