ruby3-backward-compatibility 0.1.3 → 0.2.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/CHANGELOG.md +8 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +7 -1
- data/README.md +14 -1
- data/bin/rspec +27 -0
- data/lib/ruby3_backward_compatibility/compatibility/all.rb +4 -3
- data/lib/ruby3_backward_compatibility/compatibility/i18n.rb +7 -0
- data/lib/ruby3_backward_compatibility/ruby3_keywords.rb +28 -10
- data/lib/ruby3_backward_compatibility/version.rb +1 -1
- data/ruby3-backward-compatibility.gemspec +1 -1
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a63c38a468a5c3aac7da7774abed32e9878d46ab60fcce3b842f21526b483bf
|
4
|
+
data.tar.gz: 54776548a860546d7f63426e55794e0061ccb7784712469b5fe2260d904b0b3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5648d5b980179b3a2ccac12175e96db04ac6e3d2c91f980c3da34195db91c91a730b192282e3774e31604dd8ed15e6b2fdf49fbe43cdee24e7d67c92473350dd
|
7
|
+
data.tar.gz: ee03c7f8bbdc69fb6529f0104112a85b4b2bd6a3af24b19a4d1becd27316876c66930ae7457befb6fc9055e89aaa496c96ef000bd367f068421873cd52917371
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.1] - 2022-11-04
|
4
|
+
|
5
|
+
- Fix `ruby3_keywords` for prepended methods.
|
6
|
+
|
7
|
+
## [0.2.0] - 2022-10-26
|
8
|
+
|
9
|
+
- Add `ruby3_backward_compatibility/compatibility/i18n`.
|
10
|
+
|
3
11
|
## [0.1.3] - 2022-10-25
|
4
12
|
|
5
13
|
- Allow `ruby3_keywords` to work if method is also defined in a prepended module.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby3-backward-compatibility (0.1
|
4
|
+
ruby3-backward-compatibility (0.2.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
byebug (11.1.3)
|
10
|
+
concurrent-ruby (1.1.10)
|
9
11
|
diff-lcs (1.5.0)
|
12
|
+
i18n (1.12.0)
|
13
|
+
concurrent-ruby (~> 1.0)
|
10
14
|
rake (13.0.6)
|
11
15
|
rspec (3.11.0)
|
12
16
|
rspec-core (~> 3.11.0)
|
@@ -26,6 +30,8 @@ PLATFORMS
|
|
26
30
|
x86_64-linux
|
27
31
|
|
28
32
|
DEPENDENCIES
|
33
|
+
byebug
|
34
|
+
i18n
|
29
35
|
rake (~> 13.0)
|
30
36
|
rspec (~> 3.0)
|
31
37
|
ruby3-backward-compatibility!
|
data/README.md
CHANGED
@@ -30,6 +30,8 @@ You can also require all included backports using
|
|
30
30
|
require 'ruby3-backward-compatibility/compatibility/all'
|
31
31
|
```
|
32
32
|
|
33
|
+
Note however that this will not patch anything that has not been required yet. You can always require single patches as shown below.
|
34
|
+
|
33
35
|
|
34
36
|
## List of backports
|
35
37
|
|
@@ -90,6 +92,17 @@ require 'ruby3_backward_compatibility/compatibility/erb'
|
|
90
92
|
```
|
91
93
|
|
92
94
|
|
95
|
+
### I18n
|
96
|
+
|
97
|
+
`I18n` has a few methods (`translate`, `localize`, etc.) that requires to be called with keywords.
|
98
|
+
|
99
|
+
To allow calling it with option hashes, too, use
|
100
|
+
|
101
|
+
```
|
102
|
+
require 'ruby3_backward_compatibility/compatibility/i18n'
|
103
|
+
```
|
104
|
+
|
105
|
+
|
93
106
|
### Object
|
94
107
|
|
95
108
|
The methods `Object#taint` and `Object#untaint` were no-ops for a while but started to raise deprecation warnings.
|
@@ -120,7 +133,7 @@ Psych version 4 (default for Ruby 3.1) has two changes:
|
|
120
133
|
To alias `Psych.unsafe_load` as `Psych.load`, and to allow both styles of calling `Psych.safe_load`, use
|
121
134
|
|
122
135
|
```
|
123
|
-
require 'ruby3_backward_compatibility/psych'
|
136
|
+
require 'ruby3_backward_compatibility/compatibility/psych'
|
124
137
|
```
|
125
138
|
|
126
139
|
**Attention:** There has been a very good reason why Psych renamed the `.load` method: You may never use `.load` on any external strings. It is possible to create valid YAML strings that lead to the execution of arbitrary code, so calling `YAML.load` on user input is a major security vulnerability.
|
data/bin/rspec
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 'rspec' 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) =~ /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("rspec-core", "rspec")
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'ruby3_backward_compatibility'
|
2
2
|
|
3
|
-
require 'ruby3_backward_compatibility/compatibility/erb'
|
3
|
+
require 'ruby3_backward_compatibility/compatibility/erb' if defined?(ERB)
|
4
|
+
require 'ruby3_backward_compatibility/compatibility/i18n' if defined?(I18n)
|
4
5
|
require 'ruby3_backward_compatibility/compatibility/object'
|
5
|
-
require 'ruby3_backward_compatibility/compatibility/psych'
|
6
|
+
require 'ruby3_backward_compatibility/compatibility/psych' if defined?(Psych)
|
6
7
|
require 'ruby3_backward_compatibility/compatibility/string'
|
7
|
-
require 'ruby3_backward_compatibility/compatibility/uri'
|
8
|
+
require 'ruby3_backward_compatibility/compatibility/uri' if defined?(URI)
|
@@ -1,27 +1,45 @@
|
|
1
1
|
module Ruby3BackwardCompatibility
|
2
2
|
module Ruby3Keywords
|
3
|
+
def self.find_owned_instance_method(mod, method_name)
|
4
|
+
method = mod.send(:instance_method, method_name)
|
5
|
+
while method.owner > mod
|
6
|
+
# we found the method in a prepended module
|
7
|
+
super_method = method.super_method
|
8
|
+
if super_method.nil?
|
9
|
+
warn "Called `ruby3_keywords #{method_name.inspect}` on `#{mod}`, which appears not to be the correct owner. Did you mean to call it on `#{method.owner}`?"
|
10
|
+
return method
|
11
|
+
else
|
12
|
+
method = super_method
|
13
|
+
end
|
14
|
+
end
|
15
|
+
method
|
16
|
+
end
|
17
|
+
|
3
18
|
def self.extended(by)
|
4
19
|
# prepend the anonymous module now, so the user has a chance to control where exactly we will end
|
5
20
|
# up in the prepend chain...
|
6
21
|
by.send(:_ruby3_keywords_module)
|
7
22
|
end
|
8
23
|
|
9
|
-
def ruby3_keywords(*
|
10
|
-
|
11
|
-
method_is_private = private_instance_methods.include?(
|
12
|
-
method_is_protected = protected_instance_methods.include?(
|
24
|
+
def ruby3_keywords(*method_names)
|
25
|
+
method_names.each do |method_name|
|
26
|
+
method_is_private = private_instance_methods.include?(method_name)
|
27
|
+
method_is_protected = protected_instance_methods.include?(method_name)
|
13
28
|
|
14
|
-
|
15
|
-
|
16
|
-
|
29
|
+
required_param_count = Ruby3Keywords.find_owned_instance_method(self, method_name).parameters.sum { |(kind, _name)| kind == :req ? 1 : 0 }
|
30
|
+
_ruby3_keywords_module.define_method(method_name) do |*args|
|
31
|
+
if args.last.respond_to?(:to_hash) && args.size > required_param_count
|
32
|
+
keyword_args = args.pop
|
33
|
+
super(*args, **keyword_args)
|
34
|
+
else
|
35
|
+
super(*args)
|
17
36
|
end
|
18
|
-
super(*args, **keyword_args)
|
19
37
|
end
|
20
38
|
|
21
39
|
if method_is_private
|
22
|
-
_ruby3_keywords_module.send(:private,
|
40
|
+
_ruby3_keywords_module.send(:private, method_name)
|
23
41
|
elsif method_is_protected
|
24
|
-
_ruby3_keywords_module.send(:protected,
|
42
|
+
_ruby3_keywords_module.send(:protected, method_name)
|
25
43
|
end
|
26
44
|
end
|
27
45
|
end
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
# Uncomment to register a new dependency of your gem
|
32
|
-
|
32
|
+
spec.add_development_dependency 'byebug'
|
33
33
|
|
34
34
|
# For more information and examples about making a new gem, checkout our
|
35
35
|
# guide at: https://bundler.io/guides/creating_gem.html
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby3-backward-compatibility
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Kraze
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
12
|
-
dependencies:
|
11
|
+
date: 2022-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
- tobias.kraze@makandra.de
|
@@ -26,10 +40,12 @@ files:
|
|
26
40
|
- README.md
|
27
41
|
- Rakefile
|
28
42
|
- bin/console
|
43
|
+
- bin/rspec
|
29
44
|
- bin/setup
|
30
45
|
- lib/ruby3_backward_compatibility.rb
|
31
46
|
- lib/ruby3_backward_compatibility/compatibility/all.rb
|
32
47
|
- lib/ruby3_backward_compatibility/compatibility/erb.rb
|
48
|
+
- lib/ruby3_backward_compatibility/compatibility/i18n.rb
|
33
49
|
- lib/ruby3_backward_compatibility/compatibility/object.rb
|
34
50
|
- lib/ruby3_backward_compatibility/compatibility/psych.rb
|
35
51
|
- lib/ruby3_backward_compatibility/compatibility/string.rb
|
@@ -59,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
75
|
- !ruby/object:Gem::Version
|
60
76
|
version: '0'
|
61
77
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
78
|
+
rubygems_version: 3.3.7
|
63
79
|
signing_key:
|
64
80
|
specification_version: 4
|
65
81
|
summary: Backward compatibility for Ruby 3 stdlib
|