polyfill 0.4.0 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +2 -1
- data/CHANGELOG.md +8 -0
- data/README.md +45 -1
- data/lib/polyfill.rb +52 -21
- data/lib/polyfill/utils.rb +8 -0
- data/lib/polyfill/v2_3.rb +9 -0
- data/lib/polyfill/v2_3/enumerable.rb +9 -0
- data/lib/polyfill/v2_3/enumerable/instance.rb +11 -0
- data/lib/polyfill/v2_3/enumerable/instance/chunk_while.rb +70 -0
- data/lib/polyfill/v2_3/string.rb +9 -0
- data/lib/polyfill/v2_3/string/class.rb +11 -0
- data/lib/polyfill/v2_3/string/class/new.rb +33 -0
- data/lib/polyfill/v2_4/enumerable/instance/chunk.rb +2 -0
- data/lib/polyfill/v2_4/enumerator/lazy/instance/chunk_while.rb +4 -0
- data/lib/polyfill/version.rb +1 -1
- data/polyfill.gemspec +1 -1
- metadata +11 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237acd76888542aca87f442fd066883269ddaee0
|
4
|
+
data.tar.gz: ee1bc441b77b3a6277bbcc4385703d945cc79828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccfcb0140e7d2d14da8678133dc7544984deedacac903699cbb71dbba6be6408b3560d9ee7424045a681887b409fd6da6245e53bd80becd74ae23cdf21d544ff
|
7
|
+
data.tar.gz: bc0626751a50adb7470bcd992a27b09aceb594f72b28f43833a06370e15b00b7811a5c000245b518fd11fe361e37c5527cd30f804cf276f360475089d64ad2c8
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -17,6 +17,8 @@ Right now the only update is from 2.3 to 2.4 however the goal is to go all the w
|
|
17
17
|
- [Goals](#goals)
|
18
18
|
- [Usage](#usage)
|
19
19
|
- [Implementation Table](#implementation-table)
|
20
|
+
- [2.3 to 2.4](#23-to-24)
|
21
|
+
- [2.2 to 2.3](#22-to-23)
|
20
22
|
|
21
23
|
## Caveat Emptor
|
22
24
|
|
@@ -32,7 +34,7 @@ See the [implementation table](#implementation-table) for specifics about what h
|
|
32
34
|
Add it to your Gemfile:
|
33
35
|
|
34
36
|
```ruby
|
35
|
-
gem 'polyfill', '0.
|
37
|
+
gem 'polyfill', '0.5.0'
|
36
38
|
```
|
37
39
|
|
38
40
|
Or install it manually:
|
@@ -75,6 +77,13 @@ If you want all of the methods for a particular class you can use `:all`.
|
|
75
77
|
using Polyfill(Numeric: :all)
|
76
78
|
```
|
77
79
|
|
80
|
+
Updates can be stopped at a specific version by pass it via `:version`. The
|
81
|
+
version selected must be formatted as "MAJOR.MINOR".
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
using Polyfill(version: '2.3', Numeric: :all)
|
85
|
+
```
|
86
|
+
|
78
87
|
Methods can be included in the same way. Prior to Ruby 2.4, refinements did
|
79
88
|
not work on modules. In order to get methods you'll need to include them after
|
80
89
|
the module. Calling `using` on a module will add it to all core Ruby classes
|
@@ -195,6 +204,41 @@ end
|
|
195
204
|
| TracePoint | #callee_id | No |
|
196
205
|
| Warning | #warn | No |
|
197
206
|
|
207
|
+
### 2.2 to 2.3
|
208
|
+
|
209
|
+
| Object | Method | Implemented | Notes |
|
210
|
+
| ---------------- | ------------------------ | ----------- | ----- |
|
211
|
+
| ARGF | #read_nonblock | No |
|
212
|
+
| Array | #bsearch_index | No |
|
213
|
+
| | #dig | No |
|
214
|
+
| Comparable | #== | No |
|
215
|
+
| Enumerable | #chunk | No |
|
216
|
+
| | #chunk_while | Yes |
|
217
|
+
| | #grep_v | No |
|
218
|
+
| | #slice_before | No |
|
219
|
+
| Enumerator::Lazy | #grep_v | No |
|
220
|
+
| File | .mkfifo | No |
|
221
|
+
| Hash | #< | No |
|
222
|
+
| | #<= | No |
|
223
|
+
| | #> | No |
|
224
|
+
| | #>= | No |
|
225
|
+
| | #dig | No |
|
226
|
+
| | #fetch_values | No |
|
227
|
+
| | #to_proc | No |
|
228
|
+
| IO | #advise | No |
|
229
|
+
| Kernel | #loop | No |
|
230
|
+
| Module | #deprecate_constant | No |
|
231
|
+
| NameError | #receiver | No |
|
232
|
+
| Numeric | #negative? | No |
|
233
|
+
| | #positive? | No |
|
234
|
+
| Queue | #close | No |
|
235
|
+
| String | #+@ | No |
|
236
|
+
| | #-@ | No |
|
237
|
+
| | .new | Yes |
|
238
|
+
| Struct | #dig | No |
|
239
|
+
| Thread | #name | No |
|
240
|
+
| | #name= | No |
|
241
|
+
|
198
242
|
## Contributing
|
199
243
|
|
200
244
|
Bug reports and pull requests are welcome on GitHub at https://github.com/AaronLasseigne/polyfill.
|
data/lib/polyfill.rb
CHANGED
@@ -1,38 +1,64 @@
|
|
1
1
|
require 'polyfill/version'
|
2
|
+
require 'polyfill/utils'
|
3
|
+
require 'polyfill/v2_3'
|
2
4
|
require 'polyfill/v2_4'
|
3
5
|
|
4
6
|
module Polyfill
|
7
|
+
include V2_3
|
5
8
|
include V2_4
|
6
9
|
end
|
7
10
|
|
8
11
|
def Polyfill(options) # rubocop:disable Style/MethodName
|
9
12
|
mod = Module.new
|
10
13
|
|
11
|
-
|
14
|
+
objects, others = options.partition { |key,| key[/\A[A-Z]/] }
|
15
|
+
others = others.to_h
|
16
|
+
|
17
|
+
versions = {
|
18
|
+
'2.3' => Polyfill::V2_3,
|
19
|
+
'2.4' => Polyfill::V2_4
|
20
|
+
}
|
21
|
+
desired_version = others.delete(:version) || versions.keys.max
|
22
|
+
unless versions.keys.include?(desired_version)
|
23
|
+
raise ArgumentError, "invalid value for keyword version: #{desired_version}"
|
24
|
+
end
|
25
|
+
versions.reject! do |version_number, _|
|
26
|
+
version_number > desired_version
|
27
|
+
end
|
12
28
|
|
13
29
|
unless others.empty?
|
14
30
|
raise ArgumentError, "unknown keyword: #{others.first[0]}"
|
15
31
|
end
|
16
32
|
|
17
|
-
|
33
|
+
current_ruby_version = RUBY_VERSION[/\A(\d+\.\d+)/, 1]
|
18
34
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
.
|
35
|
+
objects.each do |full_name, methods|
|
36
|
+
object_module_names = full_name.to_s.split('::')
|
37
|
+
|
38
|
+
object_modules = versions
|
39
|
+
.map do |version_number, version_module|
|
24
40
|
begin
|
25
|
-
|
41
|
+
final_module = object_module_names
|
42
|
+
.reduce(version_module) do |current_mod, name|
|
43
|
+
current_mod.const_get(name, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
[version_number, final_module]
|
26
47
|
rescue NameError
|
27
|
-
|
48
|
+
nil
|
28
49
|
end
|
29
50
|
end
|
51
|
+
.compact
|
30
52
|
|
31
|
-
if
|
32
|
-
|
53
|
+
if object_modules.empty?
|
54
|
+
raise ArgumentError, %Q("#{full_name}" is not a valid class or has no updates)
|
55
|
+
end
|
33
56
|
|
57
|
+
if methods == :all
|
34
58
|
mod.module_eval do
|
35
|
-
|
59
|
+
object_modules.each do |(version_number, object_module)|
|
60
|
+
include object_module if version_number > current_ruby_version
|
61
|
+
end
|
36
62
|
end
|
37
63
|
else
|
38
64
|
methods.each do |method|
|
@@ -58,19 +84,24 @@ def Polyfill(options) # rubocop:disable Style/MethodName
|
|
58
84
|
method_name.capitalize!
|
59
85
|
method_name.gsub!(/_(.)/) { |match| match[1].capitalize }
|
60
86
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
.const_get(type, false)
|
65
|
-
|
66
|
-
|
67
|
-
|
87
|
+
method_modules = object_modules
|
88
|
+
.map do |(version_number, object_module)|
|
89
|
+
begin
|
90
|
+
[version_number, object_module.const_get(type, false).const_get(method_name, false)]
|
91
|
+
rescue NameError
|
92
|
+
nil
|
93
|
+
end
|
68
94
|
end
|
95
|
+
.compact
|
69
96
|
|
70
|
-
|
97
|
+
if method_modules.empty?
|
98
|
+
raise ArgumentError, %Q("#{method}" is not a valid method on #{full_name} or has no updates)
|
99
|
+
end
|
71
100
|
|
72
101
|
mod.module_eval do
|
73
|
-
|
102
|
+
method_modules.each do |(version_number, method_module)|
|
103
|
+
include method_module if version_number > current_ruby_version
|
104
|
+
end
|
74
105
|
end
|
75
106
|
end
|
76
107
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module Polyfill
|
4
|
+
module V2_3
|
5
|
+
module Enumerable
|
6
|
+
module Instance
|
7
|
+
module ChunkWhile
|
8
|
+
module Method
|
9
|
+
def chunk_while
|
10
|
+
block = Proc.new
|
11
|
+
|
12
|
+
return [self] if size == 1
|
13
|
+
|
14
|
+
Enumerator.new do |yielder|
|
15
|
+
output = []
|
16
|
+
each_cons(2).with_index(1) do |(a, b), run|
|
17
|
+
if run == size - 1
|
18
|
+
if block.call(a, b)
|
19
|
+
output.push(a, b)
|
20
|
+
yielder << output
|
21
|
+
else
|
22
|
+
output.push(a)
|
23
|
+
yielder << output
|
24
|
+
yielder << [b]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
output.push(a)
|
28
|
+
unless block.call(a, b)
|
29
|
+
yielder << output
|
30
|
+
output = []
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
refine ::Array do
|
39
|
+
include Method
|
40
|
+
end
|
41
|
+
refine ::Dir do
|
42
|
+
include Method
|
43
|
+
end
|
44
|
+
refine ::Enumerator do
|
45
|
+
include Method
|
46
|
+
end
|
47
|
+
refine ::Hash do
|
48
|
+
include Method
|
49
|
+
end
|
50
|
+
refine ::IO do
|
51
|
+
include Method
|
52
|
+
end
|
53
|
+
refine ::Range do
|
54
|
+
include Method
|
55
|
+
end
|
56
|
+
refine ::StringIO do
|
57
|
+
include Method
|
58
|
+
end
|
59
|
+
refine ::Struct do
|
60
|
+
include Method
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.included(base)
|
64
|
+
base.include Method
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Polyfill
|
2
|
+
module V2_3
|
3
|
+
module String
|
4
|
+
module Class
|
5
|
+
module New
|
6
|
+
module Method
|
7
|
+
def new(*args)
|
8
|
+
hash, others = args.partition { |arg| arg.is_a?(::Hash) }
|
9
|
+
hash = hash.first
|
10
|
+
encoding = hash && hash.delete(:encoding)
|
11
|
+
|
12
|
+
if hash && !hash.keys.empty?
|
13
|
+
raise ArgumentError, "unknown keyword: #{hash.keys.first}"
|
14
|
+
end
|
15
|
+
|
16
|
+
str = super(*others)
|
17
|
+
str.encode!(encoding) if encoding
|
18
|
+
str
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
refine ::String.singleton_class do
|
23
|
+
include Method
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.included(base)
|
27
|
+
base.include Method
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/polyfill/version.rb
CHANGED
data/polyfill.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = ''
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.required_ruby_version = '>= 2.
|
16
|
+
spec.required_ruby_version = '>= 2.2'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
19
|
f.match(%r{^(test|spec|features)/})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyfill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Lasseigne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,6 +86,14 @@ files:
|
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
88
|
- lib/polyfill.rb
|
89
|
+
- lib/polyfill/utils.rb
|
90
|
+
- lib/polyfill/v2_3.rb
|
91
|
+
- lib/polyfill/v2_3/enumerable.rb
|
92
|
+
- lib/polyfill/v2_3/enumerable/instance.rb
|
93
|
+
- lib/polyfill/v2_3/enumerable/instance/chunk_while.rb
|
94
|
+
- lib/polyfill/v2_3/string.rb
|
95
|
+
- lib/polyfill/v2_3/string/class.rb
|
96
|
+
- lib/polyfill/v2_3/string/class/new.rb
|
89
97
|
- lib/polyfill/v2_4.rb
|
90
98
|
- lib/polyfill/v2_4/array.rb
|
91
99
|
- lib/polyfill/v2_4/array/instance.rb
|
@@ -196,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
204
|
requirements:
|
197
205
|
- - ">="
|
198
206
|
- !ruby/object:Gem::Version
|
199
|
-
version: '2.
|
207
|
+
version: '2.2'
|
200
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
209
|
requirements:
|
202
210
|
- - ">="
|