backports 3.18.0 → 3.23.0
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 +435 -292
- data/Gemfile +3 -16
- data/README.md +306 -156
- data/backports.gemspec +1 -1
- data/lib/backports/2.0.0.rb +1 -1
- data/lib/backports/2.1.0/module/singleton_class.rb +8 -0
- data/lib/backports/2.1.0.rb +1 -1
- data/lib/backports/2.2.0/string/unicode_normalize.rb +3 -3
- data/lib/backports/2.2.0.rb +1 -1
- data/lib/backports/2.3.0/queue/close.rb +48 -0
- data/lib/backports/2.3.0/string.rb +3 -0
- data/lib/backports/2.3.0/struct/dig.rb +2 -0
- data/lib/backports/2.3.0.rb +1 -1
- data/lib/backports/2.4.0/bignum/dup.rb +5 -0
- data/lib/backports/2.4.0/bignum.rb +3 -0
- data/lib/backports/2.4.0/string/unpack1.rb +7 -0
- data/lib/backports/2.4.0.rb +1 -1
- data/lib/backports/2.5.0/dir/children.rb +4 -0
- data/lib/backports/2.5.0/dir/each_child.rb +7 -0
- data/lib/backports/2.5.0/hash/transform_keys.rb +10 -3
- data/lib/backports/2.5.0/string/undump.rb +2 -2
- data/lib/backports/2.5.0.rb +1 -1
- data/lib/backports/2.5.rb +1 -1
- data/lib/backports/2.6.0/enumerable/chain.rb +2 -0
- data/lib/backports/2.6.0.rb +2 -2
- data/lib/backports/2.6.rb +1 -1
- data/lib/backports/2.7.0/complex/{comparision.rb → comparison.rb} +0 -0
- data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
- data/lib/backports/2.7.0/symbol/end_with.rb +9 -0
- data/lib/backports/2.7.0/symbol.rb +3 -0
- data/lib/backports/2.7.0.rb +2 -2
- data/lib/backports/3.0.0/env/except.rb +10 -0
- data/lib/backports/3.0.0/env.rb +3 -0
- data/lib/backports/3.0.0/hash/except.rb +10 -0
- data/lib/backports/3.0.0/hash/transform_keys.rb +48 -0
- data/lib/backports/3.0.0/hash.rb +3 -0
- data/lib/backports/3.0.0/ractor.rb +19 -0
- data/lib/backports/3.0.0/symbol/name.rb +21 -0
- data/lib/backports/3.0.0/symbol.rb +3 -0
- data/lib/backports/3.0.0.rb +3 -0
- data/lib/backports/3.0.rb +1 -0
- data/lib/backports/3.1.0/array/intersect.rb +16 -0
- data/lib/backports/3.1.0/array.rb +3 -0
- data/lib/backports/3.1.0/class/descendants.rb +11 -0
- data/lib/backports/3.1.0/class/subclasses.rb +11 -0
- data/lib/backports/3.1.0/class.rb +3 -0
- data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
- data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
- data/lib/backports/3.1.0/enumerable.rb +3 -0
- data/lib/backports/3.1.0/file/dirname.rb +16 -0
- data/lib/backports/3.1.0/file.rb +3 -0
- data/lib/backports/3.1.0/integer/try_convert.rb +7 -0
- data/lib/backports/3.1.0/integer.rb +3 -0
- data/lib/backports/3.1.0/match_data/match.rb +5 -0
- data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
- data/lib/backports/3.1.0/match_data.rb +3 -0
- data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
- data/lib/backports/3.1.0/struct.rb +3 -0
- data/lib/backports/3.1.0.rb +3 -0
- data/lib/backports/3.1.rb +1 -0
- data/lib/backports/latest.rb +1 -1
- data/lib/backports/ractor/cloner.rb +103 -0
- data/lib/backports/ractor/errors.rb +20 -0
- data/lib/backports/ractor/filtered_queue.rb +205 -0
- data/lib/backports/ractor/queues.rb +66 -0
- data/lib/backports/ractor/ractor.rb +272 -0
- data/lib/backports/ractor/sharing.rb +97 -0
- data/lib/backports/version.rb +1 -1
- metadata +51 -8
data/backports.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.require_paths = ["lib"]
|
24
24
|
|
25
25
|
if gem.respond_to?(:metadata)
|
26
|
-
gem.metadata['changelog_uri'] = 'https://github.com/marcandre/backports/blob/master/CHANGELOG.
|
26
|
+
gem.metadata['changelog_uri'] = 'https://github.com/marcandre/backports/blob/master/CHANGELOG.md'
|
27
27
|
gem.metadata['source_code_uri'] = 'https://github.com/marcandre/backports'
|
28
28
|
gem.metadata['bug_tracker_uri'] = 'https://github.com/marcandre/backports/issues'
|
29
29
|
end
|
data/lib/backports/2.0.0.rb
CHANGED
data/lib/backports/2.1.0.rb
CHANGED
@@ -4,7 +4,7 @@ unless String.method_defined? :unicode_normalize
|
|
4
4
|
if (Regexp.compile("[\u{11100}-\u{11102}]") rescue false)
|
5
5
|
class String
|
6
6
|
def unicode_normalize(form = :nfc)
|
7
|
-
require 'backports/tools/normalize
|
7
|
+
require 'backports/tools/normalize' unless defined? UnicodeNormalize
|
8
8
|
## The following line can be uncommented to avoid repeated checking for
|
9
9
|
## UnicodeNormalize. However, tests didn't show any noticeable speedup
|
10
10
|
## when doing this. This comment also applies to the commented out lines
|
@@ -14,13 +14,13 @@ unless String.method_defined? :unicode_normalize
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def unicode_normalize!(form = :nfc)
|
17
|
-
require 'backports/tools/normalize
|
17
|
+
require 'backports/tools/normalize' unless defined? UnicodeNormalize
|
18
18
|
# String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
|
19
19
|
replace(unicode_normalize(form))
|
20
20
|
end
|
21
21
|
|
22
22
|
def unicode_normalized?(form = :nfc)
|
23
|
-
require 'backports/tools/normalize
|
23
|
+
require 'backports/tools/normalize' unless defined? UnicodeNormalize
|
24
24
|
# String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
|
25
25
|
UnicodeNormalize.normalized?(self, form)
|
26
26
|
end
|
data/lib/backports/2.2.0.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
unless Queue.method_defined? :close
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
|
4
|
+
class ClosedQueueError < StopIteration
|
5
|
+
end
|
6
|
+
|
7
|
+
class Queue
|
8
|
+
CLOSE_MESSAGE = Object.new
|
9
|
+
|
10
|
+
def push_with_close(arg)
|
11
|
+
raise ClosedQueueError, 'queue closed' if closed?
|
12
|
+
|
13
|
+
push_without_close(arg)
|
14
|
+
end
|
15
|
+
Backports.alias_method_chain self, :push, :close
|
16
|
+
alias_method :<<, :push
|
17
|
+
alias_method :enq, :push
|
18
|
+
|
19
|
+
def pop_with_close(non_block = false)
|
20
|
+
begin
|
21
|
+
r = pop_without_close(non_block || closed?)
|
22
|
+
|
23
|
+
r unless CLOSE_MESSAGE == r
|
24
|
+
rescue ThreadError
|
25
|
+
raise if non_block || !closed?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
Backports.alias_method_chain self, :pop, :close
|
29
|
+
|
30
|
+
alias_method :shift, :pop
|
31
|
+
alias_method :deq, :pop
|
32
|
+
|
33
|
+
def close
|
34
|
+
@closed = true
|
35
|
+
2.times do
|
36
|
+
Thread.pass
|
37
|
+
num_waiting.times do
|
38
|
+
push_without_close CLOSE_MESSAGE
|
39
|
+
end
|
40
|
+
end
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def closed?
|
45
|
+
!!defined?(@closed)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/backports/2.3.0.rb
CHANGED
data/lib/backports/2.4.0.rb
CHANGED
@@ -4,4 +4,11 @@ class Dir
|
|
4
4
|
return to_enum(__method__, *args) unless block_given?
|
5
5
|
foreach(*args) { |f| yield f unless Backports::EXCLUDED_CHILDREN.include? f }
|
6
6
|
end
|
7
|
+
|
8
|
+
def each_child(&block)
|
9
|
+
return to_enum(__method__) unless block_given?
|
10
|
+
|
11
|
+
Dir.each_child(path, &block)
|
12
|
+
self
|
13
|
+
end
|
7
14
|
end unless Dir.respond_to? :each_child
|
@@ -10,9 +10,16 @@ class Hash
|
|
10
10
|
|
11
11
|
def transform_keys!
|
12
12
|
return enum_for(:transform_keys!) { size } unless block_given?
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
|
14
|
+
self[:trigger_error] = :immediately if frozen?
|
15
|
+
|
16
|
+
h = {}
|
17
|
+
begin
|
18
|
+
each do |key, value|
|
19
|
+
h[yield key] = value
|
20
|
+
end
|
21
|
+
ensure
|
22
|
+
replace(h)
|
16
23
|
end
|
17
24
|
self
|
18
25
|
end unless method_defined? :transform_keys!
|
@@ -39,9 +39,9 @@ unless String.method_defined? :undump
|
|
39
39
|
# * only allowing the first character after the \\ to not be alpha/num/space, so \\\\#@inst_var_access is ignored
|
40
40
|
# To reduce the number of calls to eval a little, we wrap everything in a (...)+ so that consecutive escapes are
|
41
41
|
# handled at the same time.
|
42
|
-
result = string.gsub(/(\\+(u\{[\w ]+\}|[^cCM]
|
42
|
+
result = string.gsub(/(\\+(u\{[\w ]+\}|[^cCM]\w*))+/) do |s|
|
43
43
|
begin
|
44
|
-
eval("\"#{s}\"")
|
44
|
+
eval("\"#{s}\"") # "body"
|
45
45
|
rescue SyntaxError => e
|
46
46
|
raise RuntimeError, e.message, e.backtrace
|
47
47
|
end
|
data/lib/backports/2.5.0.rb
CHANGED
data/lib/backports/2.5.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# require this file to load all the backports of Ruby 2.
|
1
|
+
# require this file to load all the backports of Ruby 2.5 and below
|
2
2
|
require 'backports/2.5.0'
|
@@ -8,6 +8,7 @@ unless Enumerable.method_defined? :chain
|
|
8
8
|
Enumerator = Enumerable::Enumerator unless Object.const_defined? :Enumerator # For 1.8.x
|
9
9
|
|
10
10
|
class Enumerator::Chain < Enumerator
|
11
|
+
# rubocop:disable Lint/MissingSuper
|
11
12
|
def initialize(*enums)
|
12
13
|
@enums = enums
|
13
14
|
@rewindable = -1
|
@@ -16,6 +17,7 @@ unless Enumerable.method_defined? :chain
|
|
16
17
|
# ...it checks what call of #initialize on non-initalized object returns
|
17
18
|
self # rubocop:disable Lint/Void
|
18
19
|
end
|
20
|
+
# rubocop:enable Lint/MissingSuper
|
19
21
|
|
20
22
|
def each(*args, &block)
|
21
23
|
@enums.each_with_index do |enum, i|
|
data/lib/backports/2.6.0.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
# require this file to load all the backports up to Ruby 2.
|
2
|
-
require 'backports/2.5'
|
1
|
+
# require this file to load all the backports up to Ruby 2.6
|
2
|
+
require 'backports/2.5.0'
|
3
3
|
Backports.require_relative_dir if RUBY_VERSION < '2.6'
|
data/lib/backports/2.6.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# require this file to load all the backports of Ruby 2.
|
1
|
+
# require this file to load all the backports of Ruby 2.6 and below
|
2
2
|
require 'backports/2.6.0'
|
File without changes
|
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'backports/1.9.1/enumerable/each_with_object' unless Enumerable.method_defined? :each_with_object
|
2
|
-
|
3
1
|
unless Enumerable.method_defined? :tally
|
4
2
|
module Enumerable
|
5
3
|
def tally
|
4
|
+
h = {}
|
6
5
|
# NB: By spec, tally should return default-less hash
|
7
|
-
|
6
|
+
each_entry { |item| h[item] = h.fetch(item, 0) + 1 }
|
7
|
+
|
8
|
+
h
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
data/lib/backports/2.7.0.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
# require this file to load all the backports up to Ruby 2.
|
2
|
-
require 'backports/2.6'
|
1
|
+
# require this file to load all the backports up to Ruby 2.7
|
2
|
+
require 'backports/2.6.0'
|
3
3
|
Backports.require_relative_dir if RUBY_VERSION < '2.7'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Hash
|
2
|
+
unless ({}.transform_keys(:x => 1) rescue false)
|
3
|
+
require 'backports/2.5.0/hash/transform_keys'
|
4
|
+
require 'backports/tools/alias_method_chain'
|
5
|
+
|
6
|
+
def transform_keys_with_hash_arg(hash = not_given = true, &block)
|
7
|
+
return to_enum(:transform_keys) { size } if not_given && !block
|
8
|
+
|
9
|
+
return transform_keys_without_hash_arg(&block) if not_given
|
10
|
+
|
11
|
+
h = {}
|
12
|
+
if block_given?
|
13
|
+
each do |key, value|
|
14
|
+
h[hash.fetch(key) { yield key }] = value
|
15
|
+
end
|
16
|
+
else
|
17
|
+
each do |key, value|
|
18
|
+
h[hash.fetch(key, key)] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
h
|
22
|
+
end
|
23
|
+
Backports.alias_method_chain self, :transform_keys, :hash_arg
|
24
|
+
|
25
|
+
def transform_keys_with_hash_arg!(hash = not_given = true, &block)
|
26
|
+
return enum_for(:transform_keys!) { size } if not_given && !block
|
27
|
+
|
28
|
+
return transform_keys_without_hash_arg!(&block) if not_given
|
29
|
+
|
30
|
+
h = {}
|
31
|
+
begin
|
32
|
+
if block_given?
|
33
|
+
each do |key, value|
|
34
|
+
h[hash.fetch(key) { yield key }] = value
|
35
|
+
end
|
36
|
+
else
|
37
|
+
each do |key, value|
|
38
|
+
h[hash.fetch(key, key)] = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
replace(h)
|
43
|
+
end
|
44
|
+
self
|
45
|
+
end
|
46
|
+
Backports.alias_method_chain self, :transform_keys!, :hash_arg
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
if RUBY_VERSION < '2'
|
2
|
+
warn 'Ractor not backported to Ruby 1.x'
|
3
|
+
elsif defined?(Ractor.current)
|
4
|
+
# all good
|
5
|
+
else
|
6
|
+
# Cloner:
|
7
|
+
require_relative '../2.4.0/hash/transform_values'
|
8
|
+
require_relative '../2.5.0/hash/transform_keys'
|
9
|
+
# Queues & FilteredQueue
|
10
|
+
require_relative '../2.3.0/queue/close'
|
11
|
+
|
12
|
+
class Ractor
|
13
|
+
end
|
14
|
+
|
15
|
+
module Backports
|
16
|
+
Ractor = ::Ractor
|
17
|
+
end
|
18
|
+
require_relative '../ractor/ractor'
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
unless Symbol.method_defined? :name
|
2
|
+
if ((ObjectSpace::WeakMap.new[:test] = :test) rescue false)
|
3
|
+
# WeakMaps accept symbols only in Ruby 2.7+
|
4
|
+
def Backports.symbol_names
|
5
|
+
@symbol_names ||= ObjectSpace::WeakMap.new
|
6
|
+
end
|
7
|
+
|
8
|
+
class Symbol
|
9
|
+
def name
|
10
|
+
Backports.symbol_names[self] ||= to_s.freeze
|
11
|
+
end
|
12
|
+
end
|
13
|
+
else
|
14
|
+
# For earlier Rubies, we can't pool their strings
|
15
|
+
class Symbol
|
16
|
+
def name
|
17
|
+
to_s.freeze
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'backports/3.0.0'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
unless Array.method_defined? :intersect?
|
2
|
+
require 'backports/tools/arguments'
|
3
|
+
|
4
|
+
class Array
|
5
|
+
def intersect?(array)
|
6
|
+
array = Backports.coerce_to_ary(array)
|
7
|
+
|
8
|
+
if size < array.size
|
9
|
+
smaller = self
|
10
|
+
else
|
11
|
+
smaller, array = array, self
|
12
|
+
end
|
13
|
+
(array & smaller).size > 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
unless Class.method_defined? :subclasses
|
2
|
+
require 'backports/2.1.0/module/singleton_class'
|
3
|
+
|
4
|
+
class Class
|
5
|
+
def subclasses
|
6
|
+
ObjectSpace.each_object(singleton_class).reject do |klass|
|
7
|
+
klass.superclass != self || klass.singleton_class?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
unless ([].tally({}) rescue false)
|
2
|
+
require 'backports/tools/arguments'
|
3
|
+
require 'backports/2.7.0/enumerable/tally'
|
4
|
+
require 'backports/tools/alias_method_chain'
|
5
|
+
|
6
|
+
module Enumerable
|
7
|
+
def tally_with_hash_argument(h = ::Backports::Undefined)
|
8
|
+
return tally_without_hash_argument if h.equal? ::Backports::Undefined
|
9
|
+
|
10
|
+
h = ::Backports.coerce_to_hash(h)
|
11
|
+
|
12
|
+
each_entry { |item| h[item] = h.fetch(item, 0) + 1 }
|
13
|
+
|
14
|
+
h
|
15
|
+
end
|
16
|
+
::Backports.alias_method_chain self, :tally, :hash_argument
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
unless (File.dirname("", 0) rescue false)
|
2
|
+
require 'backports/tools/alias_method_chain'
|
3
|
+
|
4
|
+
class File
|
5
|
+
def self.dirname_with_depth(path, depth = 1)
|
6
|
+
return dirname_without_depth(path) if depth == 1
|
7
|
+
|
8
|
+
raise ArgumentError, "negative depth #{depth}" if depth < 0
|
9
|
+
|
10
|
+
depth.times { path = dirname_without_depth(path) }
|
11
|
+
|
12
|
+
path
|
13
|
+
end
|
14
|
+
Backports.alias_method_chain singleton_class, :dirname, :depth
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'backports/3.1.0'
|
data/lib/backports/latest.rb
CHANGED