ruby3-backward-compatibility 0.2.0 → 0.2.1

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: b71b8fde08a5679223c87ba0b616e5dee7b2cce0ffac9f5e53baaa635b561764
4
- data.tar.gz: 2ca101eaa3eea34e3f8095300c2f7a2e19220f3c96c16f192d5aa30399044159
3
+ metadata.gz: 6a63c38a468a5c3aac7da7774abed32e9878d46ab60fcce3b842f21526b483bf
4
+ data.tar.gz: 54776548a860546d7f63426e55794e0061ccb7784712469b5fe2260d904b0b3f
5
5
  SHA512:
6
- metadata.gz: 0d8dc055e1f103f718bcb1674b408499bed79063dccde3aba4b919ec2c3cabd775d53a2b3434194b994c35a01ce7e2ec0cc0f0e97c70d8be1a0b5be368ca4ca4
7
- data.tar.gz: c56faddac8e64cb4603ddce56ad102727335e2e80370decca5808c6fad71bdb99a38b64da2d728af2b09713fcfd3ce4cb5dcdb7432b531963091127401cf875e
6
+ metadata.gz: 5648d5b980179b3a2ccac12175e96db04ac6e3d2c91f980c3da34195db91c91a730b192282e3774e31604dd8ed15e6b2fdf49fbe43cdee24e7d67c92473350dd
7
+ data.tar.gz: ee03c7f8bbdc69fb6529f0104112a85b4b2bd6a3af24b19a4d1becd27316876c66930ae7457befb6fc9055e89aaa496c96ef000bd367f068421873cd52917371
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2022-11-04
4
+
5
+ - Fix `ruby3_keywords` for prepended methods.
6
+
3
7
  ## [0.2.0] - 2022-10-26
4
8
 
5
9
  - 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.0)
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)
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
- class << self
5
- extend Ruby3BackwardCompatibility::Ruby3Keywords
3
+ module I18n::Base
4
+ extend Ruby3BackwardCompatibility::Ruby3Keywords
6
5
 
7
- ruby3_keywords :translate, :translate!, :localize, :t, :l, :transliterate
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(*methods)
10
- methods.each do |method|
11
- method_is_private = private_instance_methods.include?(method)
12
- method_is_protected = protected_instance_methods.include?(method)
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
- _ruby3_keywords_module.define_method(method) do |*args, **keyword_args|
15
- if args.last.is_a?(Hash)
16
- keyword_args.merge!(args.pop)
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, method)
40
+ _ruby3_keywords_module.send(:private, method_name)
23
41
  elsif method_is_protected
24
- _ruby3_keywords_module.send(:protected, method)
42
+ _ruby3_keywords_module.send(:protected, method_name)
25
43
  end
26
44
  end
27
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruby3BackwardCompatibility
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  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
- # spec.add_dependency 'example-gem', '~> 1.0'
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.0
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-10-26 00:00:00.000000000 Z
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,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