backports 3.16.1 → 3.18.1

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -2
  3. data/Gemfile +6 -13
  4. data/README.md +256 -251
  5. data/SECURITY.md +5 -0
  6. data/backports.gemspec +1 -1
  7. data/lib/backports.rb +6 -0
  8. data/lib/backports/1.8.7.rb +7 -6
  9. data/lib/backports/1.9.1.rb +6 -1
  10. data/lib/backports/1.9.2.rb +6 -1
  11. data/lib/backports/1.9.3.rb +6 -1
  12. data/lib/backports/2.0.0.rb +6 -1
  13. data/lib/backports/2.0.0/range/size.rb +2 -0
  14. data/lib/backports/2.1.0.rb +1 -1
  15. data/lib/backports/2.2.0.rb +1 -1
  16. data/lib/backports/2.2.0/enumerable/slice_after.rb +1 -1
  17. data/lib/backports/2.2.0/float/next_float.rb +1 -1
  18. data/lib/backports/2.2.0/float/prev_float.rb +1 -1
  19. data/lib/backports/2.2.0/method/super_method.rb +2 -2
  20. data/lib/backports/2.3.0.rb +1 -1
  21. data/lib/backports/2.3.0/array/bsearch_index.rb +1 -1
  22. data/lib/backports/2.3.0/hash/lt.rb +1 -1
  23. data/lib/backports/2.3.0/hash/lte.rb +1 -1
  24. data/lib/backports/2.3.0/hash/to_proc.rb +1 -1
  25. data/lib/backports/2.3.0/struct/dig.rb +1 -2
  26. data/lib/backports/2.4.0.rb +1 -1
  27. data/lib/backports/2.4.0/hash/transform_values.rb +2 -2
  28. data/lib/backports/2.4.0/true_class/dup.rb +0 -1
  29. data/lib/backports/2.5.0.rb +1 -1
  30. data/lib/backports/2.5.0/hash/transform_keys.rb +1 -1
  31. data/lib/backports/2.5.0/integer/sqrt.rb +2 -2
  32. data/lib/backports/2.5.0/module/alias_method.rb +0 -1
  33. data/lib/backports/2.5.0/string/undump.rb +3 -7
  34. data/lib/backports/2.5.0/struct/new.rb +1 -1
  35. data/lib/backports/2.6.0.rb +1 -1
  36. data/lib/backports/2.6.0/enumerable/chain.rb +4 -1
  37. data/lib/backports/2.6.0/hash/to_h.rb +1 -1
  38. data/lib/backports/2.6.0/range.rb +3 -0
  39. data/lib/backports/2.6.0/range/cover.rb +22 -0
  40. data/lib/backports/2.7.0.rb +1 -1
  41. data/lib/backports/2.7.0/enumerable/filter_map.rb +2 -2
  42. data/lib/backports/tools/deprecation.rb +13 -6
  43. data/lib/backports/tools/require_relative_dir.rb +6 -1
  44. data/lib/backports/version.rb +1 -1
  45. metadata +7 -4
@@ -0,0 +1,5 @@
1
+ ## Security contact information
2
+
3
+ To report a security vulnerability, please use the
4
+ [Tidelift security contact](https://tidelift.com/security).
5
+ Tidelift will coordinate the fix and disclosure.
@@ -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.rdoc'
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
@@ -1,3 +1,9 @@
1
1
  require "backports/version"
2
+
3
+ require "backports/tools/deprecation"
4
+ Backports.deprecate :require_version,
5
+ "Doing `require 'backports'` is deprecated and will not load any backport in the next major release.\n" \
6
+ "Require just the needed backports instead, or 'backports/latest'."
2
7
  require "backports/2.4"
8
+ Backports.warned[:rails] = true
3
9
  require "backports/rails"
@@ -2,10 +2,11 @@
2
2
  require "backports/tools/require_relative_dir"
3
3
  require "backports/tools/deprecation"
4
4
 
5
- Backports.deprecate :require_version,
6
- 'Requiring backports/<ruby version> is deprecated. Require just the needed backports instead'
5
+ Backports.frown_upon :require_version,
6
+ 'Requiring backports/<ruby version> is not recommended in production. Require just the needed backports instead.'
7
7
 
8
- Backports.deprecation_warned[:require_std_lib] = true
9
- require "backports/std_lib"
10
-
11
- Backports.require_relative_dir
8
+ if RUBY_VERSION < '1.8.7'
9
+ Backports.warned[:require_std_lib] = true
10
+ require "backports/std_lib"
11
+ Backports.require_relative_dir
12
+ end
@@ -1,3 +1,8 @@
1
1
  # require this file to load all the backports up to Ruby 1.9.1 (including all of 1.8.8 and below)
2
2
  require 'backports/1.8'
3
- Backports.require_relative_dir
3
+
4
+ if RUBY_VERSION < '1.9.1'
5
+ Backports.warned[:require_std_lib] = true
6
+ require "backports/std_lib"
7
+ Backports.require_relative_dir
8
+ end
@@ -1,3 +1,8 @@
1
1
  # require this file to load all the backports up to Ruby 1.9.2
2
2
  require 'backports/1.9.1'
3
- Backports.require_relative_dir
3
+
4
+ if RUBY_VERSION < '1.9.2'
5
+ Backports.warned[:require_std_lib] = true
6
+ require "backports/std_lib"
7
+ Backports.require_relative_dir
8
+ end
@@ -1,3 +1,8 @@
1
1
  # require this file to load all the backports up to Ruby 1.9.3
2
2
  require 'backports/1.9.2'
3
- Backports.require_relative_dir
3
+
4
+ if RUBY_VERSION < '1.9.3'
5
+ Backports.warned[:require_std_lib] = true
6
+ require "backports/std_lib"
7
+ Backports.require_relative_dir
8
+ end
@@ -1,3 +1,8 @@
1
1
  # require this file to load all the backports up to Ruby 2.0.0
2
2
  require 'backports/1.9'
3
- Backports.require_relative_dir
3
+
4
+ if RUBY_VERSION < '2.0'
5
+ Backports.warned[:require_std_lib] = true
6
+ require "backports/std_lib"
7
+ Backports.require_relative_dir
8
+ end
@@ -1,4 +1,6 @@
1
1
  unless Range.method_defined? :size
2
+ require 'backports/1.9.2/float/infinity'
3
+
2
4
  class Range
3
5
  def size
4
6
  return nil unless self.begin.is_a?(Numeric) && self.end.is_a?(Numeric)
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.1.0
2
2
  require 'backports/2.0'
3
- Backports.require_relative_dir
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
2
  require 'backports/2.1'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.2'
@@ -7,7 +7,7 @@ unless Enumerable.method_defined? :slice_after
7
7
  raise ArgumentError, 'both pattern and block are given' if pattern != Backports::Undefined && block
8
8
  raise ArgumentError, 'wrong number of arguments (given 0, expected 1)' if pattern == Backports::Undefined && !block
9
9
  enum = self
10
- block ||= Proc.new{|elem| pattern === elem}
10
+ block ||= proc {|elem| pattern === elem}
11
11
  Enumerator.new do |y|
12
12
  acc = []
13
13
  enum.each do |*elem|
@@ -4,7 +4,7 @@ unless Float.method_defined? :next_float
4
4
  class Float
5
5
  def next_float
6
6
  return Float::INFINITY if self == Float::INFINITY
7
- r = Backports.integer_to_float(Backports.float_to_integer(self)+1)
7
+ r = Backports.integer_to_float(Backports.float_to_integer(self) + 1)
8
8
  r == 0 ? -0.0 : r # Map +0.0 to -0.0
9
9
  end
10
10
  end
@@ -5,7 +5,7 @@ unless Float.method_defined? :prev_float
5
5
  class Float
6
6
  def prev_float
7
7
  return -Float::INFINITY if self == -Float::INFINITY
8
- Backports.integer_to_float(Backports.float_to_integer(self)-1)
8
+ Backports.integer_to_float(Backports.float_to_integer(self) - 1)
9
9
  end
10
10
  end
11
11
  end
@@ -6,10 +6,10 @@ unless Method.method_defined? :super_method
6
6
  singleton_klass = class << receiver; self; end
7
7
  call_chain = singleton_klass.ancestors
8
8
  # find current position in call chain:
9
- skip = call_chain.find_index{|c| c == owner} or return
9
+ skip = call_chain.find_index {|c| c == owner} or return
10
10
  call_chain = call_chain.drop(skip + 1)
11
11
  # find next in chain with a definition:
12
- next_index = call_chain.find_index{|c| c.method_defined? name}
12
+ next_index = call_chain.find_index {|c| c.method_defined? name}
13
13
  next_index && call_chain[next_index].instance_method(name).bind(receiver)
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.3
2
2
  require 'backports/2.2'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.3'
@@ -5,7 +5,7 @@ unless Array.method_defined? :bsearch_index
5
5
  from = 0
6
6
  to = size - 1
7
7
  satisfied = nil
8
- while from <= to do
8
+ while from <= to
9
9
  midpoint = (from + to).div(2)
10
10
  result = yield(self[midpoint])
11
11
  case result
@@ -5,7 +5,7 @@ unless Hash.method_defined? :<
5
5
  hash = Backports.coerce_to_hash(hash)
6
6
  return false unless size < hash.size
7
7
  each do |k, v|
8
- v2 = hash.fetch(k){ return false }
8
+ v2 = hash.fetch(k) { return false }
9
9
  return false unless v2 == v
10
10
  end
11
11
  true
@@ -5,7 +5,7 @@ unless Hash.method_defined? :<=
5
5
  hash = Backports.coerce_to_hash(hash)
6
6
  return false unless size <= hash.size
7
7
  each do |k, v|
8
- v2 = hash.fetch(k){ return false }
8
+ v2 = hash.fetch(k) { return false }
9
9
  return false unless v2 == v
10
10
  end
11
11
  true
@@ -2,7 +2,7 @@ unless Hash.method_defined? :to_proc
2
2
  class Hash
3
3
  def to_proc
4
4
  h = self
5
- Proc.new{|*args| h[*args]}
5
+ proc {|*args| h[*args]}
6
6
  end
7
7
  end
8
8
  end
@@ -2,11 +2,10 @@ unless Struct.method_defined? :dig
2
2
  class Struct
3
3
  def dig(key, *rest)
4
4
  return nil unless respond_to?(key)
5
- val = self.public_send(key)
5
+ val = public_send(key)
6
6
  return val if rest.empty? || val == nil
7
7
  raise TypeError, "#{val.class} does not have #dig method" unless val.respond_to? :dig
8
8
  val.dig(*rest)
9
9
  end
10
10
  end
11
11
  end
12
-
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.4
2
2
  require 'backports/2.3'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.4'
@@ -1,6 +1,6 @@
1
1
  class Hash
2
2
  def transform_values
3
- return to_enum(:transform_values){ size } unless block_given?
3
+ return to_enum(:transform_values) { size } unless block_given?
4
4
  h = {}
5
5
  each do |key, value|
6
6
  h[key] = yield value
@@ -9,7 +9,7 @@ class Hash
9
9
  end unless method_defined? :transform_values
10
10
 
11
11
  def transform_values!
12
- return to_enum(:transform_values!){ size } unless block_given?
12
+ return to_enum(:transform_values!) { size } unless block_given?
13
13
  reject!{} if frozen? # Force error triggerring if frozen, in case of empty array
14
14
  each do |key, value|
15
15
  self[key] = yield value
@@ -3,4 +3,3 @@ class TrueClass
3
3
  self
4
4
  end
5
5
  end unless (true.dup rescue false)
6
-
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.5
2
2
  require 'backports/2.4'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.5'
@@ -1,6 +1,6 @@
1
1
  class Hash
2
2
  def transform_keys
3
- return to_enum(:transform_keys){ size } unless block_given?
3
+ return to_enum(:transform_keys) { size } unless block_given?
4
4
  h = {}
5
5
  each do |key, value|
6
6
  h[yield key] = value
@@ -6,9 +6,9 @@ class Integer
6
6
  def self.sqrt(n)
7
7
  n = Backports.coerce_to_int(n)
8
8
  return Math.sqrt(n).to_i if n <= 9_999_899_999_899_999_322_536_673_279
9
- bits_shift = n.bit_length/2 + 1
9
+ bits_shift = n.bit_length / 2 + 1
10
10
  bitn_mask = root = 1 << bits_shift
11
- while true
11
+ loop do
12
12
  root ^= bitn_mask if (root * root) > n
13
13
  bitn_mask >>= 1
14
14
  return root if bitn_mask == 0
@@ -1,4 +1,3 @@
1
1
  class Module
2
2
  public :alias_method
3
3
  end
4
-
@@ -6,14 +6,10 @@ unless String.method_defined? :undump
6
6
  raise 'string contains null byte' if string["\0"]
7
7
  raise 'non-ASCII character detected' unless string.ascii_only?
8
8
 
9
- #raise '.force_encoding("...") format is not supported by backports' if string.match(/\A".*"\.force_encoding\("[^"]*"\)\z/)
10
- match = string.match(/\A(".*?"?)(?:\.force_encoding\("([^"]*)"\))?\z/)
11
- if match
12
- string = match[1]
13
- encoding = match[2]
14
- else
9
+ match = string.match(/\A(".*?"?)(?:\.force_encoding\("([^"]*)"\))?\z/) or
15
10
  raise %(invalid dumped string; not wrapped with '"' nor '"...".force_encoding("...")' form)
16
- end
11
+ string = match[1]
12
+ encoding = match[2]
17
13
 
18
14
  # Ruby 1.9.3 does weird things to encoding during gsub
19
15
  encoding ||= string.encoding.to_s
@@ -19,5 +19,5 @@ if RUBY_VERSION >= '2.0.0' && (Struct.new(:a, :keyword_init => true) && false re
19
19
  end
20
20
  Backports.alias_method_chain(self, :new, :keyword_init)
21
21
  end
22
- ]
22
+ ], nil, __FILE__, __LINE__ - 19
23
23
  end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.5
2
2
  require 'backports/2.5'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.6'
@@ -11,7 +11,10 @@ unless Enumerable.method_defined? :chain
11
11
  def initialize(*enums)
12
12
  @enums = enums
13
13
  @rewindable = -1
14
- self
14
+ # This self is necessary to pass RubySpec,
15
+ # See rubyspec/core/enumerator/chain/initialize_spec.rb
16
+ # ...it checks what call of #initialize on non-initalized object returns
17
+ self # rubocop:disable Lint/Void
15
18
  end
16
19
 
17
20
  def each(*args, &block)
@@ -1,6 +1,6 @@
1
1
  require 'backports/2.0.0/hash/to_h' unless Hash.method_defined? :to_h
2
2
 
3
- if {:n => true}.to_h{[:ok, true]}[:n]
3
+ if {:n => true}.to_h {[:ok, true]}[:n]
4
4
  require 'backports/tools/alias_method_chain'
5
5
  require 'backports/2.1.0/array/to_h'
6
6
 
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,22 @@
1
+ unless (1..4).cover?(2..3)
2
+ require 'backports/tools/alias_method_chain'
3
+
4
+ class Range
5
+ def cover_with_range_compatibility?(what)
6
+ return cover_without_range_compatibility?(what) unless what.is_a?(Range)
7
+
8
+ left = self.begin <=> what.begin
9
+ right = self.end <=> what.end
10
+ return false unless left && right
11
+
12
+ left <= 0 && (
13
+ right >= 1 ||
14
+ right == 0 && (!exclude_end? || what.exclude_end?) ||
15
+ what.exclude_end? && what.begin.is_a?(Integer) &&
16
+ what.end.is_a?(Integer) && cover_without_range_compatibility?(what.end - 1)
17
+ )
18
+ end
19
+ Backports.alias_method_chain self, :cover?, :range_compatibility
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  # require this file to load all the backports up to Ruby 2.5
2
2
  require 'backports/2.6'
3
- Backports.require_relative_dir
3
+ Backports.require_relative_dir if RUBY_VERSION < '2.7'
@@ -5,10 +5,10 @@ unless Enumerable.method_defined? :filter_map
5
5
  def filter_map
6
6
  return to_enum(:filter_map) unless block_given?
7
7
 
8
- each_with_object([]) { |item, res|
8
+ each_with_object([]) do |item, res|
9
9
  processed = yield(item)
10
10
  res << processed if processed
11
- }
11
+ end
12
12
  end
13
13
  end
14
14
  end
@@ -1,12 +1,19 @@
1
1
  module Backports
2
2
  class << self
3
- attr_accessor :deprecation_warned
4
- Backports.deprecation_warned = {}
3
+ attr_accessor :warned # private
4
+ Backports.warned = {}
5
5
 
6
- def deprecate kind, msg
7
- return if deprecation_warned[kind]
8
- warn msg
9
- deprecation_warned[kind] = msg
6
+ def frown_upon kind, msg
7
+ warn kind, msg if $VERBOSE
10
8
  end
9
+
10
+ def warn kind, msg
11
+ return if warned[kind]
12
+ super msg
13
+ warned[kind] = msg
14
+ end
15
+
16
+ alias_method :deprecate, :warn
17
+
11
18
  end
12
19
  end
@@ -7,7 +7,12 @@ module Backports
7
7
  compact.
8
8
  sort.
9
9
  each do |f|
10
- require short_path + f
10
+ path = '../../' + short_path + f
11
+ if Kernel.private_method_defined?(:require_relative)
12
+ require_relative path
13
+ else
14
+ require File.expand_path(path)
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.16.1" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.18.1" 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.16.1
4
+ version: 3.18.1
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-02-16 00:00:00.000000000 Z
11
+ date: 2020-06-23 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.
@@ -22,6 +22,7 @@ files:
22
22
  - Gemfile
23
23
  - LICENSE.txt
24
24
  - README.md
25
+ - SECURITY.md
25
26
  - backports.gemspec
26
27
  - lib/backports.rb
27
28
  - lib/backports/1.8.7.rb
@@ -509,6 +510,8 @@ files:
509
510
  - lib/backports/2.6.0/method/compose.rb
510
511
  - lib/backports/2.6.0/proc.rb
511
512
  - lib/backports/2.6.0/proc/compose.rb
513
+ - lib/backports/2.6.0/range.rb
514
+ - lib/backports/2.6.0/range/cover.rb
512
515
  - lib/backports/2.6.rb
513
516
  - lib/backports/2.7.0.rb
514
517
  - lib/backports/2.7.0/array.rb
@@ -563,7 +566,7 @@ homepage: http://github.com/marcandre/backports
563
566
  licenses:
564
567
  - MIT
565
568
  metadata:
566
- changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.rdoc
569
+ changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.md
567
570
  source_code_uri: https://github.com/marcandre/backports
568
571
  bug_tracker_uri: https://github.com/marcandre/backports/issues
569
572
  post_install_message:
@@ -581,7 +584,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
581
584
  - !ruby/object:Gem::Version
582
585
  version: '0'
583
586
  requirements: []
584
- rubygems_version: 3.0.3
587
+ rubygems_version: 3.1.2
585
588
  signing_key:
586
589
  specification_version: 4
587
590
  summary: Backports of Ruby features for older Ruby.