ruby3-backward-compatibility 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +5 -5
- data/lib/ruby3_backward_compatibility/{ruby3_keywords.rb → callable_with_hash.rb} +10 -10
- data/lib/ruby3_backward_compatibility/compatibility/i18n.rb +2 -2
- data/lib/ruby3_backward_compatibility/compatibility/string.rb +2 -2
- data/lib/ruby3_backward_compatibility/version.rb +1 -1
- data/lib/ruby3_backward_compatibility.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d863bc999c8d389ecc066c1e205d29599f8126296c177937bf61e054245765ee
|
4
|
+
data.tar.gz: bd87ac80c634fa8292c8a7f09bf7cbb6c2c1e84e7a8eae02fab1ade564c05b12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06b02c646e5f753bf7e7f6ad908fc7687c11d96eace311e4e962264b9087e2f7c9b7f5613d72893d384b8ebb3c66a7dec27297e7e383dea4f675b44d80f220fb
|
7
|
+
data.tar.gz: 84cb5c14e91f7c0272f7a56527aada55ea2785db50278584e3152265a43d435f68f4803f22693ffb750d2e6ca173df2fbd6a9771bd5181570eed87489b02092b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.0.0] - 2022-12-01
|
4
|
+
|
5
|
+
- Now 1.0, adhering to semantic versioning.
|
6
|
+
- Breaking: Rename `ruby3_keywords` to `callable_with_hash`.
|
7
|
+
|
3
8
|
## [0.3.0] - 2022-11-22
|
4
9
|
|
5
10
|
- Security fix: `ruby3_backward_compatibility/compatibility/psych` no longer aliases YAML.load to YAML.safe_load.
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Note however that this will not patch anything that has not been required yet. Y
|
|
35
35
|
|
36
36
|
## List of backports
|
37
37
|
|
38
|
-
###
|
38
|
+
### Ruby 3 keyword arguments
|
39
39
|
|
40
40
|
One breaking change in Ruby 3 is that methods defined using keyword arguments have to be called with keyword arguments, not with option hashes. For example
|
41
41
|
|
@@ -50,7 +50,7 @@ Ruby3Class.new.some_method(foo: 'bar') # works
|
|
50
50
|
Ruby3Class.new.some_method({ foo: 'bar' }) # raises an ArgumentError
|
51
51
|
```
|
52
52
|
|
53
|
-
To fix this for arbitrary methods, you can use the `
|
53
|
+
To fix this for arbitrary methods, you can use the `callable_with_hash` method included in this gem, like this:
|
54
54
|
|
55
55
|
```
|
56
56
|
require 'ruby3_backward_compatibility'
|
@@ -58,9 +58,9 @@ require 'ruby3_backward_compatibility'
|
|
58
58
|
class Ruby3Class
|
59
59
|
# reopen the class
|
60
60
|
|
61
|
-
extend Ruby3BackwardCompatibility::
|
61
|
+
extend Ruby3BackwardCompatibility::CallableWithHash
|
62
62
|
|
63
|
-
|
63
|
+
callable_with_hash :some_method
|
64
64
|
end
|
65
65
|
|
66
66
|
Ruby3Class.new.some_method(foo: 'bar') # still works
|
@@ -69,7 +69,7 @@ Ruby3Class.new.some_method({ foo: 'bar' }) # now works as well
|
|
69
69
|
|
70
70
|
This will wrap the given method and convert a hash given as the last argument into keywords, similar to how it worked in Ruby 2.
|
71
71
|
|
72
|
-
*Note:* In case the method is also defined in a prepended module, you need to put the `extend Ruby3BackwardCompatibility::
|
72
|
+
*Note:* In case the method is also defined in a prepended module, you need to put the `extend Ruby3BackwardCompatibility::CallableWithHash` above the `prepend`.
|
73
73
|
|
74
74
|
### ERB
|
75
75
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Ruby3BackwardCompatibility
|
2
|
-
module
|
2
|
+
module CallableWithHash
|
3
3
|
def self.find_owned_instance_method(mod, method_name, ignore_missing: false)
|
4
4
|
method = begin
|
5
5
|
mod.send(:instance_method, method_name)
|
@@ -11,7 +11,7 @@ module Ruby3BackwardCompatibility
|
|
11
11
|
# we found the method in a prepended module
|
12
12
|
super_method = method.super_method
|
13
13
|
if super_method.nil?
|
14
|
-
warn "Called `
|
14
|
+
warn "Called `callable_with_hash #{method_name.inspect}` on `#{mod}`, which appears not to be the correct owner. Did you mean to call it on `#{method.owner}`?"
|
15
15
|
return method
|
16
16
|
else
|
17
17
|
method = super_method
|
@@ -23,19 +23,19 @@ module Ruby3BackwardCompatibility
|
|
23
23
|
def self.extended(by)
|
24
24
|
# prepend the anonymous module now, so the user has a chance to control where exactly we will end
|
25
25
|
# up in the prepend chain...
|
26
|
-
by.send(:
|
26
|
+
by.send(:_ruby3_callable_with_hash_module)
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def callable_with_hash(*method_names, ignore_missing: false)
|
30
30
|
method_names.each do |method_name|
|
31
31
|
method_is_private = private_instance_methods.include?(method_name)
|
32
32
|
method_is_protected = protected_instance_methods.include?(method_name)
|
33
33
|
|
34
|
-
method =
|
34
|
+
method = CallableWithHash.find_owned_instance_method(self, method_name, ignore_missing: ignore_missing)
|
35
35
|
next unless method
|
36
36
|
|
37
37
|
required_param_count = method.parameters.sum { |(kind, _name)| kind == :req ? 1 : 0 }
|
38
|
-
|
38
|
+
_ruby3_callable_with_hash_module.define_method(method_name) do |*args, &block|
|
39
39
|
if args.last.respond_to?(:to_hash) && args.size > required_param_count
|
40
40
|
keyword_args = args.pop
|
41
41
|
super(*args, **keyword_args, &block)
|
@@ -45,17 +45,17 @@ module Ruby3BackwardCompatibility
|
|
45
45
|
end
|
46
46
|
|
47
47
|
if method_is_private
|
48
|
-
|
48
|
+
_ruby3_callable_with_hash_module.send(:private, method_name)
|
49
49
|
elsif method_is_protected
|
50
|
-
|
50
|
+
_ruby3_callable_with_hash_module.send(:protected, method_name)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
-
def
|
58
|
-
@
|
57
|
+
def _ruby3_callable_with_hash_module
|
58
|
+
@_ruby3_callable_with_hash_module ||= begin
|
59
59
|
mod = Module.new
|
60
60
|
prepend mod
|
61
61
|
mod
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
|
3
3
|
module I18n::Base
|
4
|
-
extend Ruby3BackwardCompatibility::
|
4
|
+
extend Ruby3BackwardCompatibility::CallableWithHash
|
5
5
|
|
6
|
-
|
6
|
+
callable_with_hash :translate, :translate!, :localize, :t, :l, :transliterate, ignore_missing: true
|
7
7
|
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: 0.
|
4
|
+
version: 1.0.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: 2022-
|
11
|
+
date: 2022-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- bin/rspec
|
44
44
|
- bin/setup
|
45
45
|
- lib/ruby3_backward_compatibility.rb
|
46
|
+
- lib/ruby3_backward_compatibility/callable_with_hash.rb
|
46
47
|
- lib/ruby3_backward_compatibility/compatibility/all.rb
|
47
48
|
- lib/ruby3_backward_compatibility/compatibility/erb.rb
|
48
49
|
- lib/ruby3_backward_compatibility/compatibility/i18n.rb
|
@@ -50,7 +51,6 @@ files:
|
|
50
51
|
- lib/ruby3_backward_compatibility/compatibility/psych.rb
|
51
52
|
- lib/ruby3_backward_compatibility/compatibility/string.rb
|
52
53
|
- lib/ruby3_backward_compatibility/compatibility/uri.rb
|
53
|
-
- lib/ruby3_backward_compatibility/ruby3_keywords.rb
|
54
54
|
- lib/ruby3_backward_compatibility/version.rb
|
55
55
|
- ruby3-backward-compatibility.gemspec
|
56
56
|
homepage: https://github.com/makandra/ruby3-backward-compatibility
|