backports 3.18.2 → 3.19.0

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: 178159f05e53f3b3fc1c828a000e71a5f1860b058cf91c651f49b252ce05f130
4
- data.tar.gz: b088578f04bd15de52d682caa6f9ba4fbe819a8d51fb66f89a8323019e40ca49
3
+ metadata.gz: 7545e11eda01d2ea412b51973b69d70ede1544ad14d11511085f80d51f1e9924
4
+ data.tar.gz: 9cfd27da7f62e6606b73afa3770e25eb7fd90d254eb95c242fe375e38a10f078
5
5
  SHA512:
6
- metadata.gz: 14187360b8a6f5a85f61a1ab8cac5121ce6bbc468dab22cefd8ec73c85cf834d1865a83da9fb3e2ddb3ec2adee5cbf90e4e8d22c254e14d543e5d9491d166736
7
- data.tar.gz: b3456f62ca139a0beec8d4f8b3faff8ed7616da4fc3e31083bc9647a816c7c55ef8eb568f4f9dd101ff62e1279cc90e8f32ec67a67ccb14be3e902ef9af07ba1
6
+ metadata.gz: 64f2afe9cf49d42da0122399c765cf8e9eda203145957fa3a296f169ac36c1f471cd08d3384d397b987c9cf368947e4f5db6fe0ba460d0fbad014ff0a40e35e8
7
+ data.tar.gz: 0d52dd7e5b79dd2dd225ddff67a34bdd329141e4c0ce924369271ce9e4fde48e2462452940e18110d64b6d9c10f3fd8c4cd5d57a8944317a8124c0b37f22887a
@@ -6,7 +6,28 @@ 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 2020)](https://github.com/marcandre/backports/issues/139) might drop support for Ruby < 2.2, please comment.
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.19.0](https://github.com/marcandre/backports/compare/v3.19.0...v3.18.2) - 2020-12-28
12
+
13
+ ### Added
14
+
15
+ * Ruby 3.0 backports
16
+
17
+ * Env
18
+ * `except`
19
+
20
+ * Hash
21
+ * `except`
22
+ * `transform_keys`, `transform_keys!` (with hash argument)
23
+
24
+ * Symbol
25
+ * `name`
26
+
27
+ * Ruby 2.3 backports
28
+
29
+ * Queue
30
+ * `close`, `closed?` (affects `push`, `pop` and aliases)
10
31
 
11
32
  ## [3.18.2](https://github.com/marcandre/backports/compare/v3.18.0...v3.18.2) - 2020-08-26
12
33
 
@@ -14,7 +35,7 @@ Note: [Next major version (X-mas 2020)](https://github.com/marcandre/backports/i
14
35
 
15
36
  Require per ruby version now properly requiring 2.3.0 backports for `String` [#152]
16
37
 
17
- ## [3.18.2](https://github.com/marcandre/backports/compare/v3.18.1...v3.18.2) - 2020-08-26
38
+ ## [3.18.1](https://github.com/marcandre/backports/compare/v3.18.1...v3.18.2) - 2020-66-22
18
39
 
19
40
  ### Fixed
20
41
 
data/Gemfile CHANGED
@@ -9,8 +9,8 @@ group :test do
9
9
  gem 'test-unit'
10
10
  end
11
11
 
12
- if RUBY_VERSION >= '2.3.0'
12
+ if RUBY_VERSION >= '2.4.0'
13
13
  group :development do
14
- gem 'rubocop', '~> 0.80.0'
14
+ gem 'rubocop', '~> 1.1.0'
15
15
  end
16
16
  end
data/README.md CHANGED
@@ -9,7 +9,7 @@ The goal of 'backports' is to make it easier to write ruby code that runs
9
9
  across different versions of Ruby.
10
10
 
11
11
  Note: [Next major version (X-mas
12
- 2020)](https://github.com/marcandre/backports/issues/139) will drop support
12
+ 2021?)](https://github.com/marcandre/backports/issues/139) may drop support
13
13
  for Ruby < 2.2.
14
14
 
15
15
  ## Loading backports
@@ -109,6 +109,18 @@ itself, JRuby and Rubinius.
109
109
 
110
110
  # Complete List of backports
111
111
 
112
+ ## Ruby 3.0 backports
113
+
114
+ #### Env
115
+ - `except`
116
+
117
+ #### Hash
118
+ - `except`
119
+ - `transform_keys`, `transform_keys!` (with hash argument)
120
+
121
+ #### Symbol
122
+ - `name`
123
+
112
124
  ## Ruby 2.7 backports
113
125
 
114
126
  #### Array
@@ -206,13 +218,16 @@ itself, JRuby and Rubinius.
206
218
  - `compact`, `compact!`
207
219
  - `transform_values`, `transform_values!`
208
220
 
221
+ #### Queue
222
+ - `close`, `closed?`
223
+
209
224
  #### Regexp
210
225
  - `match?`
211
226
 
212
227
  #### String
213
228
  - `match?`
214
229
 
215
- #### FalseClass, Fixnum, Float, NilClass, TrueClass
230
+ #### FalseClass, Fixnum, Bignum, Float, NilClass, TrueClass
216
231
  - `dup`
217
232
 
218
233
  ## Ruby 2.3 backports
@@ -1,5 +1,5 @@
1
1
  # require this file to load all the backports up to Ruby 2.0.0
2
- require 'backports/1.9'
2
+ require 'backports/1.9.3'
3
3
 
4
4
  if RUBY_VERSION < '2.0'
5
5
  Backports.warned[:require_std_lib] = true
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.1.0
2
- require 'backports/2.0'
2
+ require 'backports/2.0.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.1'
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.2
2
- require 'backports/2.1'
2
+ require 'backports/2.1.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.2'
@@ -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.rb' unless defined? UnicodeNormalize
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.rb' unless defined? UnicodeNormalize
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.rb' unless defined? UnicodeNormalize
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
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.3
2
- require 'backports/2.2'
2
+ require 'backports/2.2.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.3'
@@ -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
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.4
2
- require 'backports/2.3'
2
+ require 'backports/2.3.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.4'
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,5 @@
1
+ class Bignum
2
+ def dup
3
+ self
4
+ end
5
+ end unless ((1 << 64).dup rescue false)
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.5
2
- require 'backports/2.4'
2
+ require 'backports/2.4.0'
3
3
  Backports.require_relative_dir if RUBY_VERSION < '2.5'
@@ -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
- merge!({}) if frozen?
14
- keys.each do |key|
15
- self[yield(key)] = delete(key)
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!
@@ -9,7 +9,7 @@ class Integer
9
9
  bits_shift = n.bit_length / 2 + 1
10
10
  bitn_mask = root = 1 << bits_shift
11
11
  loop do
12
- root ^= bitn_mask if (root * root) > n
12
+ root ^= bitn_mask if (root * root) > n # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
13
13
  bitn_mask >>= 1
14
14
  return root if bitn_mask == 0
15
15
  root |= bitn_mask
@@ -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][\w]*))+/) do |s|
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
@@ -1,2 +1,2 @@
1
- # require this file to load all the backports of Ruby 2.4 and below
1
+ # require this file to load all the backports of Ruby 2.5 and below
2
2
  require 'backports/2.5.0'
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 2.5
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|
@@ -1,2 +1,2 @@
1
- # require this file to load all the backports of Ruby 2.4 and below
1
+ # require this file to load all the backports of Ruby 2.6 and below
2
2
  require 'backports/2.6.0'
@@ -1,3 +1,3 @@
1
- # require this file to load all the backports up to Ruby 2.5
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,3 @@
1
+ # require this file to load all the backports up to Ruby 3.0
2
+ require 'backports/2.7.0'
3
+ Backports.require_relative_dir if RUBY_VERSION < '3.0'
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,10 @@
1
+ class << ENV
2
+ def except(*keys)
3
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
4
+ h = {}
5
+ keys.each { |key| h[key] = true }
6
+ keys = h
7
+ end
8
+ reject { |key, _value| keys.include? key}
9
+ end
10
+ end unless ENV.respond_to? :except
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,10 @@
1
+ class Hash
2
+ def except(*keys)
3
+ if keys.size > 4 && size > 4 # index if O(m*n) is big
4
+ h = {}
5
+ keys.each { |key| h[key] = true }
6
+ keys = h
7
+ end
8
+ reject { |key, _value| keys.include? key}
9
+ end
10
+ end unless Hash.method_defined? :except
@@ -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,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,11 @@
1
+ unless Symbol.method_defined? :name
2
+ def Backports.symbol_names
3
+ @symbol_names ||= ObjectSpace::WeakMap.new
4
+ end
5
+
6
+ class Symbol
7
+ def name
8
+ Backports.symbol_names[self] ||= to_s.freeze
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'backports/3.0.0'
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.18.2" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.19.0" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.18.2
4
+ version: 3.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc-André Lafortune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Essential backports that enable many of the nice features of Ruby for
14
14
  earlier versions.
@@ -425,6 +425,7 @@ files:
425
425
  - lib/backports/2.3.0/numeric.rb
426
426
  - lib/backports/2.3.0/numeric/negative.rb
427
427
  - lib/backports/2.3.0/numeric/positive.rb
428
+ - lib/backports/2.3.0/queue/close.rb
428
429
  - lib/backports/2.3.0/string.rb
429
430
  - lib/backports/2.3.0/string/uminus.rb
430
431
  - lib/backports/2.3.0/string/uplus.rb
@@ -432,6 +433,8 @@ files:
432
433
  - lib/backports/2.3.0/struct/dig.rb
433
434
  - lib/backports/2.3.rb
434
435
  - lib/backports/2.4.0.rb
436
+ - lib/backports/2.4.0/bignum.rb
437
+ - lib/backports/2.4.0/bignum/dup.rb
435
438
  - lib/backports/2.4.0/comparable.rb
436
439
  - lib/backports/2.4.0/comparable/clamp.rb
437
440
  - lib/backports/2.4.0/enumerable.rb
@@ -529,6 +532,15 @@ files:
529
532
  - lib/backports/2.7.0/time/ceil.rb
530
533
  - lib/backports/2.7.0/time/floor.rb
531
534
  - lib/backports/2.7.rb
535
+ - lib/backports/3.0.0.rb
536
+ - lib/backports/3.0.0/env.rb
537
+ - lib/backports/3.0.0/env/except.rb
538
+ - lib/backports/3.0.0/hash.rb
539
+ - lib/backports/3.0.0/hash/except.rb
540
+ - lib/backports/3.0.0/hash/transform_keys.rb
541
+ - lib/backports/3.0.0/symbol.rb
542
+ - lib/backports/3.0.0/symbol/name.rb
543
+ - lib/backports/3.0.rb
532
544
  - lib/backports/basic_object.rb
533
545
  - lib/backports/force/array_map.rb
534
546
  - lib/backports/force/enumerable_map.rb
@@ -585,7 +597,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
585
597
  - !ruby/object:Gem::Version
586
598
  version: '0'
587
599
  requirements: []
588
- rubygems_version: 3.1.2
600
+ rubygems_version: 3.1.4
589
601
  signing_key:
590
602
  specification_version: 4
591
603
  summary: Backports of Ruby features for older Ruby.