backports 3.16.1 → 3.17.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: 2118947fbadf4aa13865b5ceec7be5ed416ab4ada72647c076bcc277c034abfc
4
- data.tar.gz: c6237a756a22de924ef77c9b0027a55d55a9c2386286ef2ba86c8967b75cb2e3
3
+ metadata.gz: a3d24b48165778d61941516a41ffd588433f8481e2271c203faf13b00633f625
4
+ data.tar.gz: 9ea6f26974c57c1ee4656cf3067d4ae274b66d939327125f729dce56523e1e94
5
5
  SHA512:
6
- metadata.gz: 324ce7e19fabc56f101dcf2b567f1b3e2b75b7d165351a6b8526df050d8646a13a3645b5aa747e51ded19f9e486adea6b9612f31798a5660135ededc837f2888
7
- data.tar.gz: 6455e9141e9a2fb66a68be72184caedc36529027459590d35be9ebc462967424ed6cb736b2fd836b2f998e616985e473c895d27f56fafd55c4ee13f838e761ec
6
+ metadata.gz: b9ad712f51352110a758778522f443f24a668434ddbf78f7b8c0580935bb7ccd7465663ce27b6656cf0e785347f960a46b384daed7eb05329afa049a3ec8f228
7
+ data.tar.gz: 557038055c3775404fb13c546c4ea0caaa8ddcd1a631c2a232f044345dbce5ae38dbe183de86c288b0b39e8d961201d5512923f6d596f03b9afa662b0b64c39b
@@ -8,11 +8,26 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
8
8
 
9
9
  Note: [Next major version (X-mas 2020)](https://github.com/marcandre/backports/issues/139) will drop support for Ruby < 2.2.
10
10
 
11
+ ## [3.17.0](https://github.com/marcandre/backports/compare/v3.16.1...v3.16.2) - 2020-03-06
12
+
13
+ ### Added
14
+
15
+ * Ruby 2.6 backports
16
+
17
+ * Range
18
+ * `cover?` (with `Range` argument)
19
+
20
+ ### Changed
21
+
22
+ Requiring features for a particular version of Ruby or `latest` is un-deprecated but
23
+ instead simply warned in verbose mode.
24
+
11
25
  ## [3.16.1](https://github.com/marcandre/backports/compare/v3.16.0...v3.16.1) - 2020-02-16
12
26
 
13
27
  ### Deprecated
14
28
 
15
- Officially deprecate requiring features for a particular version of Ruby, `latest`, `std_lib` or `rails` backports
29
+ Officially deprecate requiring features for a particular version of Ruby, `latest`, `std_lib` or `rails` backports.
30
+ Partly un-deprecated in 3.17.0!
16
31
 
17
32
  ### Fixed
18
33
 
data/Gemfile CHANGED
@@ -14,6 +14,12 @@ group :test do
14
14
  gem 'test-unit', '~>2.1.1.0'
15
15
  end
16
16
 
17
+ if RUBY_VERSION >= '2.3.0'
18
+ group :development do
19
+ gem 'rubocop', '~> 0.80.0'
20
+ end
21
+ end
22
+
17
23
  # Declare any dependencies that are still in development here instead of in
18
24
  # your gemspec. These might include edge Rails or gems from your path or
19
25
  # Git. Remember to move these dependencies to your gemspec before releasing
data/README.md CHANGED
@@ -1,4 +1,4 @@
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)
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
3
  Yearning to use some of the new cool features in Ruby 2.7 while using 2.3.x?
4
4
  Have some legacy code in Ruby 1.8 but can't live without `flat_map`?
@@ -35,20 +35,22 @@ Class:
35
35
  This will make sure that Hash responds to dig, fetch_values, <, <=, >, >= and
36
36
  to_proc
37
37
 
38
- ### Up to a specific Ruby version (deprecated)
38
+ ### Up to a specific Ruby version (for quick coding)
39
39
 
40
- Although this is deprecated, you can load all backports up to a specific version.
40
+ You can load all backports up to a specific version.
41
41
  For example, to bring any
42
- version of Ruby mostly up to Ruby 2.4.0's standards:
42
+ version of Ruby mostly up to Ruby 2.7.0's standards:
43
43
 
44
- require 'backports/2.4.0'
44
+ require 'backports/2.7.0'
45
45
 
46
46
  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 2.4.0 (for all versions of Ruby)!
47
+ all the way up to Ruby 2.7.0 (for all versions of Ruby)!
48
48
 
49
- While it is not recommended, you may `require 'backports/latest'` as a
50
- shortcut to the latest Ruby version supported. This is equivalent to the
51
- deprecated `require 'backports'`.
49
+ You may `require 'backports/latest'` as a
50
+ shortcut to the latest Ruby version supported.
51
+
52
+ *Note*: For production / public gems, it is highly recommended you only require
53
+ the backports you need explicitly.
52
54
 
53
55
  *Note*: Although I am a Ruby committer, this gem is a personal project and is
54
56
  not endorsed by ruby-core.
@@ -153,6 +155,9 @@ itself, JRuby and Rubinius.
153
155
  * Proc
154
156
  * +<<+, +>>+
155
157
 
158
+ * Range
159
+ * `cover?` (with `Range` argument)
160
+
156
161
  ## Ruby 2.5 backports
157
162
 
158
163
  * Array
@@ -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.
@@ -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,10 @@
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
8
+ Backports.warned[:require_std_lib] = true
9
9
  require "backports/std_lib"
10
10
 
11
11
  Backports.require_relative_dir
@@ -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
@@ -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,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,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
+ ], __FILE__, __LINE__
23
23
  end
@@ -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
@@ -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
@@ -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.17.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.16.1
4
+ version: 3.17.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-02-16 00:00:00.000000000 Z
11
+ date: 2020-03-06 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