ruby3-backward-compatibility 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +3 -1
- data/README.md +1 -1
- data/bin/rspec +27 -0
- data/lib/ruby3_backward_compatibility/compatibility/i18n.rb +3 -5
- 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 +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f41ca19f2c12e6f2d275f62bf3079587ffcbd70f455f7b12761cd3ed91a8cf6e
|
4
|
+
data.tar.gz: 9c3d76a042555bcadb4452486bcd4948a1702f3a7920fcb600cbe4976497aa46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f76bec36e842805432da6e44f3eef1c5bc6ebc4671fd73c849f4af770b8e0a8ba0643e696c3cf1b473c3154ea5f3b20bc67320903c283206929cac03bbdca268
|
7
|
+
data.tar.gz: 57880ff6f4dab6bdcf19979dc7fd4faf4500f6103fa0eb5f38dfc2f1d10aaadd53b65d4baf81028ae05c86da2a370b5128a6b8a5f96fef103ef808e92297d490
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.2] - 2022-11-10
|
4
|
+
|
5
|
+
- Fix `ruby3_keywords` to pass blocks.
|
6
|
+
|
7
|
+
## [0.2.1] - 2022-11-04
|
8
|
+
|
9
|
+
- Fix `ruby3_keywords` for prepended methods.
|
10
|
+
|
3
11
|
## [0.2.0] - 2022-10-26
|
4
12
|
|
5
13
|
- Add `ruby3_backward_compatibility/compatibility/i18n`.
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby3-backward-compatibility (0.2.
|
4
|
+
ruby3-backward-compatibility (0.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
byebug (11.1.3)
|
9
10
|
concurrent-ruby (1.1.10)
|
10
11
|
diff-lcs (1.5.0)
|
11
12
|
i18n (1.12.0)
|
@@ -29,6 +30,7 @@ PLATFORMS
|
|
29
30
|
x86_64-linux
|
30
31
|
|
31
32
|
DEPENDENCIES
|
33
|
+
byebug
|
32
34
|
i18n
|
33
35
|
rake (~> 13.0)
|
34
36
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -133,7 +133,7 @@ Psych version 4 (default for Ruby 3.1) has two changes:
|
|
133
133
|
To alias `Psych.unsafe_load` as `Psych.load`, and to allow both styles of calling `Psych.safe_load`, use
|
134
134
|
|
135
135
|
```
|
136
|
-
require 'ruby3_backward_compatibility/psych'
|
136
|
+
require 'ruby3_backward_compatibility/compatibility/psych'
|
137
137
|
```
|
138
138
|
|
139
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,9 +1,7 @@
|
|
1
1
|
require 'i18n'
|
2
2
|
|
3
|
-
module I18n
|
4
|
-
|
5
|
-
extend Ruby3BackwardCompatibility::Ruby3Keywords
|
3
|
+
module I18n::Base
|
4
|
+
extend Ruby3BackwardCompatibility::Ruby3Keywords
|
6
5
|
|
7
|
-
|
8
|
-
end
|
6
|
+
ruby3_keywords :translate, :translate!, :localize, :t, :l, :transliterate
|
9
7
|
end
|
@@ -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, &block|
|
31
|
+
if args.last.respond_to?(:to_hash) && args.size > required_param_count
|
32
|
+
keyword_args = args.pop
|
33
|
+
super(*args, **keyword_args, &block)
|
34
|
+
else
|
35
|
+
super(*args, &block)
|
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.2.
|
4
|
+
version: 0.2.2
|
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-10
|
12
|
-
dependencies:
|
11
|
+
date: 2022-11-10 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,6 +40,7 @@ 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
|