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 +4 -4
- data/CHANGELOG.md +16 -1
- data/Gemfile +6 -0
- data/README.md +14 -9
- data/SECURITY.md +5 -0
- data/lib/backports.rb +6 -0
- data/lib/backports/1.8.7.rb +3 -3
- data/lib/backports/2.2.0/enumerable/slice_after.rb +1 -1
- data/lib/backports/2.2.0/float/next_float.rb +1 -1
- data/lib/backports/2.2.0/float/prev_float.rb +1 -1
- data/lib/backports/2.2.0/method/super_method.rb +2 -2
- data/lib/backports/2.3.0/array/bsearch_index.rb +1 -1
- data/lib/backports/2.3.0/hash/lt.rb +1 -1
- data/lib/backports/2.3.0/hash/lte.rb +1 -1
- data/lib/backports/2.3.0/hash/to_proc.rb +1 -1
- data/lib/backports/2.3.0/struct/dig.rb +1 -2
- data/lib/backports/2.4.0/hash/transform_values.rb +2 -2
- data/lib/backports/2.4.0/true_class/dup.rb +0 -1
- data/lib/backports/2.5.0/hash/transform_keys.rb +1 -1
- data/lib/backports/2.5.0/integer/sqrt.rb +2 -2
- data/lib/backports/2.5.0/module/alias_method.rb +0 -1
- data/lib/backports/2.5.0/string/undump.rb +3 -7
- data/lib/backports/2.5.0/struct/new.rb +1 -1
- data/lib/backports/2.6.0/enumerable/chain.rb +4 -1
- data/lib/backports/2.6.0/hash/to_h.rb +1 -1
- data/lib/backports/2.6.0/range.rb +3 -0
- data/lib/backports/2.6.0/range/cover.rb +22 -0
- data/lib/backports/2.7.0/enumerable/filter_map.rb +2 -2
- data/lib/backports/tools/deprecation.rb +13 -6
- data/lib/backports/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3d24b48165778d61941516a41ffd588433f8481e2271c203faf13b00633f625
|
4
|
+
data.tar.gz: 9ea6f26974c57c1ee4656cf3067d4ae274b66d939327125f729dce56523e1e94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9ad712f51352110a758778522f443f24a668434ddbf78f7b8c0580935bb7ccd7465663ce27b6656cf0e785347f960a46b384daed7eb05329afa049a3ec8f228
|
7
|
+
data.tar.gz: 557038055c3775404fb13c546c4ea0caaa8ddcd1a631c2a232f044345dbce5ae38dbe183de86c288b0b39e8d961201d5512923f6d596f03b9afa662b0b64c39b
|
data/CHANGELOG.md
CHANGED
@@ -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 (
|
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
41
|
For example, to bring any
|
42
|
-
version of Ruby mostly up to Ruby 2.
|
42
|
+
version of Ruby mostly up to Ruby 2.7.0's standards:
|
43
43
|
|
44
|
-
require 'backports/2.
|
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.
|
47
|
+
all the way up to Ruby 2.7.0 (for all versions of Ruby)!
|
48
48
|
|
49
|
-
|
50
|
-
shortcut to the latest Ruby version supported.
|
51
|
-
|
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
|
data/SECURITY.md
ADDED
data/lib/backports.rb
CHANGED
@@ -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"
|
data/lib/backports/1.8.7.rb
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
require "backports/tools/require_relative_dir"
|
3
3
|
require "backports/tools/deprecation"
|
4
4
|
|
5
|
-
Backports.
|
6
|
-
'Requiring backports/<ruby version> is
|
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.
|
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 ||=
|
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
|
@@ -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 =
|
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
|
@@ -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
|
-
|
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
|
@@ -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
|
-
|
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
|
-
|
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
|
@@ -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)
|
@@ -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([])
|
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 :
|
4
|
-
Backports.
|
3
|
+
attr_accessor :warned # private
|
4
|
+
Backports.warned = {}
|
5
5
|
|
6
|
-
def
|
7
|
-
|
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
|
data/lib/backports/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Backports
|
2
|
-
VERSION = "3.
|
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.
|
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-
|
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
|