ruby3-backward-compatibility 0.2.1 → 0.2.3

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: 6a63c38a468a5c3aac7da7774abed32e9878d46ab60fcce3b842f21526b483bf
4
- data.tar.gz: 54776548a860546d7f63426e55794e0061ccb7784712469b5fe2260d904b0b3f
3
+ metadata.gz: dea3d1f265f31f9581b5f558b2df2a2e8ba10dc76665f793e05b450fd6470daf
4
+ data.tar.gz: e601975de9ae5fdb6081c67546c8ad00f1381b8769c299802ad714b179eb62bb
5
5
  SHA512:
6
- metadata.gz: 5648d5b980179b3a2ccac12175e96db04ac6e3d2c91f980c3da34195db91c91a730b192282e3774e31604dd8ed15e6b2fdf49fbe43cdee24e7d67c92473350dd
7
- data.tar.gz: ee03c7f8bbdc69fb6529f0104112a85b4b2bd6a3af24b19a4d1becd27316876c66930ae7457befb6fc9055e89aaa496c96ef000bd367f068421873cd52917371
6
+ metadata.gz: c470ac7894bada53f9aea7518db643551e216126331ae20760532199c24f96fa088afb98955346d8424fa27cd20a18fefb0712a35075e63c1d97d51733dc913b
7
+ data.tar.gz: 4e5396c9b4281c4955e90a5ea318dde169937881899a865d6b66ce382753a669f9c9a8cef1bf840d11b5d6a736f5825948845334ef01b90feb77d6e6ef3e1949
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.3] - 2022-11-10
4
+
5
+ - Add `ignore_missing: true` option for `ruby3_keywords` to not crash on missing methods.
6
+ - Fix `ruby3_backward_compatibility/compatibility/i18n` to not crash when used with older I18n versions.
7
+
8
+ ## [0.2.2] - 2022-11-10
9
+
10
+ - Fix `ruby3_keywords` to pass blocks.
11
+
3
12
  ## [0.2.1] - 2022-11-04
4
13
 
5
14
  - Fix `ruby3_keywords` for prepended methods.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby3-backward-compatibility (0.2.1)
4
+ ruby3-backward-compatibility (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,5 +3,5 @@ require 'i18n'
3
3
  module I18n::Base
4
4
  extend Ruby3BackwardCompatibility::Ruby3Keywords
5
5
 
6
- ruby3_keywords :translate, :translate!, :localize, :t, :l, :transliterate
6
+ ruby3_keywords :translate, :translate!, :localize, :t, :l, :transliterate, ignore_missing: true
7
7
  end
@@ -1,7 +1,12 @@
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)
3
+ def self.find_owned_instance_method(mod, method_name, ignore_missing: false)
4
+ method = begin
5
+ mod.send(:instance_method, method_name)
6
+ rescue NameError
7
+ return if ignore_missing
8
+ raise NameError, "method '#{method_name}' is not defined"
9
+ end
5
10
  while method.owner > mod
6
11
  # we found the method in a prepended module
7
12
  super_method = method.super_method
@@ -21,18 +26,21 @@ module Ruby3BackwardCompatibility
21
26
  by.send(:_ruby3_keywords_module)
22
27
  end
23
28
 
24
- def ruby3_keywords(*method_names)
29
+ def ruby3_keywords(*method_names, ignore_missing: false)
25
30
  method_names.each do |method_name|
26
31
  method_is_private = private_instance_methods.include?(method_name)
27
32
  method_is_protected = protected_instance_methods.include?(method_name)
28
33
 
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|
34
+ method = Ruby3Keywords.find_owned_instance_method(self, method_name, ignore_missing: ignore_missing)
35
+ next unless method
36
+
37
+ required_param_count = method.parameters.sum { |(kind, _name)| kind == :req ? 1 : 0 }
38
+ _ruby3_keywords_module.define_method(method_name) do |*args, &block|
31
39
  if args.last.respond_to?(:to_hash) && args.size > required_param_count
32
40
  keyword_args = args.pop
33
- super(*args, **keyword_args)
41
+ super(*args, **keyword_args, &block)
34
42
  else
35
- super(*args)
43
+ super(*args, &block)
36
44
  end
37
45
  end
38
46
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruby3BackwardCompatibility
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.3'
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: 0.2.1
4
+ version: 0.2.3
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-04 00:00:00.000000000 Z
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug