backports 3.18.1 → 3.20.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 +47 -1
- data/Gemfile +2 -2
- data/README.md +34 -14
- data/lib/backports/2.0.0.rb +1 -1
- data/lib/backports/2.1.0.rb +1 -1
- data/lib/backports/2.2.0.rb +1 -1
- data/lib/backports/2.2.0/string/unicode_normalize.rb +3 -3
- data/lib/backports/2.3.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.4.0.rb +1 -1
- data/lib/backports/2.4.0/bignum.rb +3 -0
- data/lib/backports/2.4.0/bignum/dup.rb +5 -0
- data/lib/backports/2.5.0.rb +1 -1
- 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.rb +1 -1
- data/lib/backports/2.6.0.rb +2 -2
- data/lib/backports/2.6.0/enumerable/chain.rb +2 -0
- data/lib/backports/2.6.rb +1 -1
- data/lib/backports/2.7.0.rb +2 -2
- data/lib/backports/3.0.0.rb +3 -0
- data/lib/backports/3.0.0/env.rb +3 -0
- data/lib/backports/3.0.0/env/except.rb +10 -0
- data/lib/backports/3.0.0/hash.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/ractor.rb +19 -0
- data/lib/backports/3.0.0/symbol.rb +3 -0
- data/lib/backports/3.0.0/symbol/name.rb +11 -0
- data/lib/backports/3.0.rb +1 -0
- data/lib/backports/ractor/cloner.rb +94 -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 +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5c6feae3c15c70a78dda33abcb10c737393eb6898d1756c8f3da4e5f604b25
|
4
|
+
data.tar.gz: 3339a5a0ae48803b9853627c096790f555a3a8f852af7b66c4331f683fcaac55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d843af1e7bd02fe062f600df7b130c37b2ce41bf178831049bbcd57fadbb9cac1c73d9bf4feebca71dcb39998492442083822d60c1691e1e67f195e21005ea97
|
7
|
+
data.tar.gz: f37e52397480aeb259cf469093980cdef01500e845b94fbe90d67864f37323d2dcdbd59fa308ada90cc7c1820a02b20c07c4a647e986840f0c9222c1b4313a35
|
data/CHANGELOG.md
CHANGED
@@ -6,7 +6,53 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
Note: [Next major version (X-mas
|
9
|
+
Note: [Next major version (X-mas 2021?)](https://github.com/marcandre/backports/issues/139) may drop support for Ruby < 2.2, please comment.
|
10
|
+
|
11
|
+
## [3.20.1](https://github.com/marcandre/backports/compare/v3.20.0...v3.20.1) - 2021-01-03
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
* Added `Ractor.[]` and `[]=` [#161]
|
16
|
+
* `Ractor.current` fixed from threads [#161]
|
17
|
+
|
18
|
+
## [3.20.0](https://github.com/marcandre/backports/compare/v3.19.0...v3.20.0) - 2020-12-30
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
Ractor backport (all methods)
|
23
|
+
|
24
|
+
## [3.19.0](https://github.com/marcandre/backports/compare/v3.18.2...v3.19.0) - 2020-12-28
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
* Ruby 3.0 backports
|
29
|
+
|
30
|
+
* Env
|
31
|
+
* `except`
|
32
|
+
|
33
|
+
* Hash
|
34
|
+
* `except`
|
35
|
+
* `transform_keys`, `transform_keys!` (with hash argument)
|
36
|
+
|
37
|
+
* Symbol
|
38
|
+
* `name`
|
39
|
+
|
40
|
+
* Ruby 2.3 backports
|
41
|
+
|
42
|
+
* Queue
|
43
|
+
* `close`, `closed?` (affects `push`, `pop` and aliases)
|
44
|
+
|
45
|
+
## [3.18.2](https://github.com/marcandre/backports/compare/v3.18.0...v3.18.2) - 2020-08-26
|
46
|
+
|
47
|
+
### Fixed
|
48
|
+
|
49
|
+
Require per ruby version now properly requiring 2.3.0 backports for `String` [#152]
|
50
|
+
|
51
|
+
## [3.18.1](https://github.com/marcandre/backports/compare/v3.18.1...v3.18.2) - 2020-06-22
|
52
|
+
|
53
|
+
### Fixed
|
54
|
+
|
55
|
+
Fixed Changelog URI in gem manifest
|
10
56
|
|
11
57
|
## [3.18.0](https://github.com/marcandre/backports/compare/v3.17.2...v3.18.0) - 2020-06-22
|
12
58
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Backports Library [<img src="https://travis-ci.org/marcandre/backports.svg?branch=master">](https://travis-ci.org/marcandre/backports) [<img src="https://badge.fury.io/rb/backports.svg" alt="Gem Version" />](http://badge.fury.io/rb/backports) [![Tidelift](https://tidelift.com/badges/package/rubygems/backports)](https://tidelift.com/subscription/pkg/rubygems-backports?utm_source=rubygems-backports&utm_medium=referral&utm_campaign=readme)
|
2
2
|
|
3
|
-
Yearning to
|
3
|
+
Yearning to write a gem using some new cool features in Ruby 3.0 while
|
4
|
+
still supporting Ruby 2.5.x?
|
4
5
|
Have some legacy code in Ruby 1.8 but can't live without `flat_map`?
|
5
6
|
|
6
7
|
This gem is for you!
|
@@ -9,20 +10,20 @@ The goal of 'backports' is to make it easier to write ruby code that runs
|
|
9
10
|
across different versions of Ruby.
|
10
11
|
|
11
12
|
Note: [Next major version (X-mas
|
12
|
-
|
13
|
+
2021?)](https://github.com/marcandre/backports/issues/139) may drop support
|
13
14
|
for Ruby < 2.2.
|
14
15
|
|
15
16
|
## Loading backports
|
16
17
|
|
17
18
|
### Explicitly (recommended)
|
18
19
|
|
19
|
-
For example, if you want to use transform_values and transform_keys
|
20
|
+
For example, if you want to use `transform_values` and `transform_keys`, even in
|
20
21
|
Ruby implementations that don't include it:
|
21
22
|
|
22
23
|
require 'backports/2.4.0/hash/transform_values'
|
23
24
|
require 'backports/2.5.0/hash/transform_keys'
|
24
25
|
|
25
|
-
This will enable Hash#transform_values and Hash#transform_keys
|
26
|
+
This will enable `Hash#transform_values` and `Hash#transform_keys`, using the
|
26
27
|
native versions if available or otherwise provide a pure Ruby version.
|
27
28
|
|
28
29
|
### By Module
|
@@ -32,19 +33,17 @@ Class:
|
|
32
33
|
|
33
34
|
require 'backports/2.3.0/hash'
|
34
35
|
|
35
|
-
This will make sure that Hash responds to dig
|
36
|
-
to_proc
|
36
|
+
This will make sure that Hash responds to `dig`, `fetch_values`, `to_proc` and comparisons.
|
37
37
|
|
38
38
|
### Up to a specific Ruby version (for quick coding)
|
39
39
|
|
40
40
|
You can load all backports up to a specific version.
|
41
|
-
For example, to bring any
|
42
|
-
version of Ruby mostly up to Ruby 2.7.0's standards:
|
41
|
+
For example, to bring any version of Ruby mostly up to Ruby 3.0.0's standards:
|
43
42
|
|
44
|
-
require 'backports/
|
43
|
+
require 'backports/3.0.0'
|
45
44
|
|
46
45
|
This will bring in all the features of 1.8.7 and many features of Ruby 1.9.x
|
47
|
-
all the way up to Ruby
|
46
|
+
all the way up to Ruby 3.0.0 (for all versions of Ruby)!
|
48
47
|
|
49
48
|
You may `require 'backports/latest'` as a
|
50
49
|
shortcut to the latest Ruby version supported.
|
@@ -109,6 +108,24 @@ itself, JRuby and Rubinius.
|
|
109
108
|
|
110
109
|
# Complete List of backports
|
111
110
|
|
111
|
+
## Ruby 3.0 backports
|
112
|
+
|
113
|
+
#### Env
|
114
|
+
- `except`
|
115
|
+
|
116
|
+
#### Hash
|
117
|
+
- `except`
|
118
|
+
- `transform_keys`, `transform_keys!` (with hash argument)
|
119
|
+
|
120
|
+
#### Ractor
|
121
|
+
- All methods, with the caveats:
|
122
|
+
- uses Ruby's `Thread` internally
|
123
|
+
- will not raise some errors when `Ractor` would (in particular `Ractor::IsolationError`)
|
124
|
+
- supported in Ruby 2.0+ only
|
125
|
+
|
126
|
+
#### Symbol
|
127
|
+
- `name`
|
128
|
+
|
112
129
|
## Ruby 2.7 backports
|
113
130
|
|
114
131
|
#### Array
|
@@ -118,7 +135,7 @@ itself, JRuby and Rubinius.
|
|
118
135
|
- `clamp` (with range)
|
119
136
|
|
120
137
|
#### Complex
|
121
|
-
-
|
138
|
+
- `<=>`
|
122
139
|
|
123
140
|
#### Enumerable
|
124
141
|
- `filter_map`
|
@@ -150,10 +167,10 @@ itself, JRuby and Rubinius.
|
|
150
167
|
- `then`
|
151
168
|
|
152
169
|
#### Method
|
153
|
-
-
|
170
|
+
- `<<`, `>>`
|
154
171
|
|
155
172
|
#### Proc
|
156
|
-
-
|
173
|
+
- `<<`, `>>`
|
157
174
|
|
158
175
|
#### Range
|
159
176
|
- `cover?` (with `Range` argument)
|
@@ -206,13 +223,16 @@ itself, JRuby and Rubinius.
|
|
206
223
|
- `compact`, `compact!`
|
207
224
|
- `transform_values`, `transform_values!`
|
208
225
|
|
226
|
+
#### Queue
|
227
|
+
- `close`, `closed?`
|
228
|
+
|
209
229
|
#### Regexp
|
210
230
|
- `match?`
|
211
231
|
|
212
232
|
#### String
|
213
233
|
- `match?`
|
214
234
|
|
215
|
-
#### FalseClass, Fixnum, Float, NilClass, TrueClass
|
235
|
+
#### FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
|
216
236
|
- `dup`
|
217
237
|
|
218
238
|
## Ruby 2.3 backports
|
data/lib/backports/2.0.0.rb
CHANGED
data/lib/backports/2.1.0.rb
CHANGED
data/lib/backports/2.2.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.3.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.4.0.rb
CHANGED
data/lib/backports/2.5.0.rb
CHANGED
@@ -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.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'
|
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'
|
@@ -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.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'
|
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
|