backports 3.7.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -15
  2. data/.travis.yml +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.rdoc +37 -5
  5. data/Rakefile +15 -7
  6. data/lib/backports.rb +0 -1
  7. data/lib/backports/1.8.7.rb +1 -1
  8. data/lib/backports/1.8.7/argf/lines.rb +1 -1
  9. data/lib/backports/1.8.7/dir/foreach.rb +1 -1
  10. data/lib/backports/1.9.2/stdlib/matrix.rb +2 -1
  11. data/lib/backports/2.2.0/kernel.rb +3 -0
  12. data/lib/backports/2.2.0/kernel/itself.rb +7 -0
  13. data/lib/backports/2.2.0/method.rb +3 -0
  14. data/lib/backports/2.2.0/method/curry.rb +9 -0
  15. data/lib/backports/2.2.0/string.rb +3 -0
  16. data/lib/backports/2.2.0/string/unicode_normalize.rb +29 -0
  17. data/lib/backports/2.3.0/array.rb +3 -0
  18. data/lib/backports/2.3.0/array/bsearch_index.rb +32 -0
  19. data/lib/backports/2.3.0/array/dig.rb +10 -0
  20. data/lib/backports/2.3.0/enumerable.rb +3 -0
  21. data/lib/backports/2.3.0/enumerable/chunk_while.rb +27 -0
  22. data/lib/backports/2.3.0/enumerable/grep_v.rb +17 -0
  23. data/lib/backports/2.3.0/hash.rb +3 -0
  24. data/lib/backports/2.3.0/hash/dig.rb +10 -0
  25. data/lib/backports/2.3.0/hash/fetch_values.rb +9 -0
  26. data/lib/backports/2.3.0/hash/gt.rb +10 -0
  27. data/lib/backports/2.3.0/hash/gte.rb +10 -0
  28. data/lib/backports/2.3.0/hash/lt.rb +14 -0
  29. data/lib/backports/2.3.0/hash/lte.rb +14 -0
  30. data/lib/backports/2.3.0/hash/to_proc.rb +8 -0
  31. data/lib/backports/2.3.0/numeric.rb +3 -0
  32. data/lib/backports/2.3.0/numeric/negative.rb +7 -0
  33. data/lib/backports/2.3.0/numeric/positive.rb +7 -0
  34. data/lib/backports/2.3.0/string/uminus.rb +7 -0
  35. data/lib/backports/2.3.0/string/uplus.rb +7 -0
  36. data/lib/backports/2.3.0/struct.rb +3 -0
  37. data/lib/backports/2.3.0/struct/dig.rb +12 -0
  38. data/lib/backports/2.4.0/comparable/clamp.rb +0 -1
  39. data/lib/backports/2.4.0/regexp/match.rb +11 -0
  40. data/lib/backports/2.4.0/string/match.rb +11 -0
  41. data/lib/backports/rails.rb +0 -1
  42. data/lib/backports/tools/normalize.rb +1322 -0
  43. data/lib/backports/version.rb +1 -1
  44. data/spec/tags/1.8.6/core/array/bsearch_index_spec.rb +1 -0
  45. data/spec/tags/1.8.6/core/string/uplus_spec.rb +1 -0
  46. data/spec/tags/1.8.7/core/array/bsearch_index_spec.rb +1 -0
  47. data/spec/tags/1.8.7/core/string/uplus_spec.rb +1 -0
  48. data/spec/tags/1.9.1/core/array/bsearch_index_spec.rb +1 -0
  49. data/spec/tags/1.9.1/core/string/uplus_spec.rb +1 -0
  50. data/spec/tags/1.9.2/core/array/bsearch_index_spec.rb +1 -0
  51. data/spec/tags/1.9.2/core/method/curry_spec.rb +1 -0
  52. data/spec/tags/1.9.2/core/string/uplus_spec.rb +1 -0
  53. data/spec/tags/1.9.3/core/array/bsearch_index_spec.rb +1 -0
  54. data/spec/tags/1.9.3/core/io/write_spec.rb +3 -0
  55. data/spec/tags/1.9.3/core/method/curry_spec.rb +1 -0
  56. data/spec/tags/1.9.3/core/string/uplus_spec.rb +1 -0
  57. data/spec/tags/2.0.0/core/string/uplus_spec.rb +1 -0
  58. data/spec/tags/2.1.0/core/string/uplus_spec.rb +1 -0
  59. data/spec/tags/2.2.0/core/string/uplus_spec.rb +1 -0
  60. data/spec/tags/2.3.0/core/string/uplus_spec.rb +1 -0
  61. metadata +94 -25
  62. data/lib/backports/2.3.0/.git_keep +0 -0
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTAxODgxMGVjYjhjMWY4YThjZDA0OWU2MjMxZGJkNzA2Y2QyNzM3ZA==
5
- data.tar.gz: !binary |-
6
- OWJhNGEwNDRiZDhlYjlkOWMyZDg0Yzc2ZTI3YTk3Y2Y3Y2IzYmViYQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- OWJlMTk0N2FjY2RmN2RlYzFkZWY5ZTZlYjQxNjMxNmQ1NzBkMzkwMTgwYzk3
10
- MWYyYzMwMTM4M2VhMmZiM2M2MzY3YTEzMmM5M2M0ODNjMzFiMzk4NThmMzU1
11
- ZDVkNGQwN2QzZWY0ZjFhZDM4NDAzMWIyMjk3NWRhMzU1Y2I0YTM=
12
- data.tar.gz: !binary |-
13
- ODMwZGRiZmY0NTU1MjI3ZDM1Zjc4NmU5YTlhOWE0NTM1NjQzNWFjN2RjMDJh
14
- ODRkMjMzNjM3MjU4OWJlNDhmOTMwZjI0MmQ2Mjg2Njk0ZWM0ODI3MjE2ZGY0
15
- ZWZiMWI1MTM5ODNiN2UyNTNkMzFhYjg3NTZiNmI0OWFhNjM3YzI=
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e52f4dda0021643064728943ece934fa701b457d
4
+ data.tar.gz: 620cd311f3db83478a252654022a73ef7384b4eb
5
+ SHA512:
6
+ metadata.gz: 0e5eb5b37f37fed2f483bddaf03872e368423073a09bfbc936b58c644d68d29b6afd8d23ed143b4c1b5220189b24b8e171aa5821d118b9f454fdd4d99f1878a9
7
+ data.tar.gz: 39c8f04ef376fbfdd113e98a2d1c366a4dd1990214fdd5e0ad7cd26f6ccd1ffe9c078627dde3783a89d4840a3beefc38a70c4fb00d66211e0b33729c7ee2b312
@@ -3,6 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - "1.8.7"
5
5
  - "1.9.2"
6
+ - "1.9.3"
6
7
  - "2.0.0"
7
8
  - "2.1.0"
8
9
  - "2.2.0"
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- backports (3.7.0)
4
+ backports (3.8.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -28,13 +28,13 @@ This will bring in all the features of 1.8.7 and many features of Ruby 1.9.x and
28
28
  Goals for backported features:
29
29
  1. Won't break older code
30
30
  2. Pure Ruby (no C extensions)
31
- 3. Pass RubySpec[http://github.com/rubyspec/rubyspec]
31
+ 3. Pass ruby/spec[https://github.com/ruby/spec]
32
32
 
33
33
  Let's be a bit more precise about the "breaking code" business. It is of course entirely possible that code will break, for example some core methods are monkeypatched or if the code relies on a certain call raising an exception. Example: <tt>[42].sample rescue "dum example"</tt> will return <tt>"dum example"</tt> without this gem and <tt>42</tt> with it.
34
34
 
35
35
  A real incompatibility is, for example, <tt>Module::instance_methods</tt> which returns strings in 1.8 and symbols in 1.9. No change can be made without the risk of breaking existing code. Such incompatibilities are left unchanged, although you can require some of these changes in addition (see below)
36
36
 
37
- All features of 1.8.7 are backported (well, almost all, see the exception list bellow), and many of the following versions up to 2.1
37
+ All features of 1.8.7 are backported (well, almost all, see the exception list bellow), and many of the following versions
38
38
 
39
39
  For historical reasons, some generic and self-contained features of active-support are also included. By simple I mean that String#camelcase is there, but #pluralize isn't. These will probably be removed in the future, so it's recommended to require those directly from active_support.
40
40
 
@@ -64,8 +64,7 @@ With bundler, add to your Gemfile:
64
64
  gem 'backports', :require => false
65
65
 
66
66
  Run <tt>bundle install</tt> and require the desired backports.
67
-
68
- Compatible with Ruby 1.8.6-2.4, JRuby and Rubinius.
67
+ Compatible with Ruby itself, JRuby and Rubinius.
69
68
 
70
69
  = Complete List of backports
71
70
 
@@ -73,6 +72,31 @@ Compatible with Ruby 1.8.6-2.4, JRuby and Rubinius.
73
72
 
74
73
  * Comparable
75
74
  * +clamp+
75
+ * Regexp
76
+ * +match?+
77
+ * String
78
+ * +match?+
79
+
80
+ == Ruby 2.3 backports
81
+
82
+ * Array
83
+ * +bsearch_index+
84
+ * +dig+
85
+ * Enumerable
86
+ * +chunk_while+
87
+ * +grep_v+
88
+ * Hash
89
+ * +dig+
90
+ * +fetch_values+
91
+ * +to_proc+
92
+ * <=, <, >=, >
93
+ * Numeric
94
+ * +negative?+
95
+ * +positive?+
96
+ * String
97
+ * unary + and -
98
+ * Struct
99
+ * +dig+
76
100
 
77
101
  == Ruby 2.2 backports
78
102
 
@@ -82,6 +106,14 @@ Compatible with Ruby 1.8.6-2.4, JRuby and Rubinius.
82
106
  * Float
83
107
  * +prev_float+
84
108
  * +next_float+
109
+ * Kernel
110
+ * +itself+
111
+ * Method
112
+ * +curry+
113
+ * String
114
+ * +unicode_normalize+
115
+ * +unicode_normalize!+
116
+ * +unicode_normalize?+
85
117
 
86
118
  == Ruby 2.1 backports
87
119
 
@@ -302,7 +334,7 @@ Thanks for the bug reports and patches, in particular the repeat offenders:
302
334
  * Konstantin Haase ( rkh[https://github.com/rkh])
303
335
  * Roger Pack ( rdp[http://github.com/rdp] )
304
336
 
305
- The best way to submit a patch is to also submit a patch to RubySpec[https://github.com/rubyspec/rubyspec] and then a patch to backports that make it pass the spec. To test rubyspec:
337
+ The best way to submit a patch is to also submit a patch to ruby/spec[https://github.com/ruby/spec] and then a patch to backports that make it pass the spec. To test rubyspec:
306
338
 
307
339
  git submodule init && git submodule update # => pulls rubyspecs
308
340
  rake spec[array/bsearch] # => tests Array#bsearch
data/Rakefile CHANGED
@@ -65,8 +65,10 @@ task :spec, :path, :action do |t, args|
65
65
  mspec_cmds(args[:path], 'frozen_old_spec', args[:action]) do |cmd, path|
66
66
  specs.run(cmd, path)
67
67
  end
68
- mspec_cmds(args[:path], 'spec', args[:action]) do |cmd, path|
69
- specs.run(cmd, path)
68
+ unless RUBY_VERSION < '1.9' # Give up entirely on running new specs in 1.8.x, mainly because of {hash: 'syntax'}
69
+ mspec_cmds(args[:path], 'spec', args[:action]) do |cmd, path|
70
+ specs.run(cmd, path)
71
+ end
70
72
  end
71
73
  specs.report
72
74
  fail unless specs.success?
@@ -97,7 +99,11 @@ DEPENDENCIES = Hash.new([]).merge!(
97
99
  '1.9.2/enumerable/each_entry' => 'backports/1.8.7/enumerable/each_with_index',
98
100
  '2.0.0/hash/to_h' => 'backports/1.9.1/hash/default_proc',
99
101
  '2.2.0/float/next_float' => 'backports/2.2.0/float/prev_float',
100
- '2.2.0/float/prev_float' => 'backports/2.2.0/float/next_float'
102
+ '2.2.0/float/prev_float' => 'backports/2.2.0/float/next_float',
103
+ '2.3.0/array/bsearch_index' => ['backports/2.3.0/array/dig', 'backports/2.3.0/hash/dig'],
104
+ '2.3.0/array/dig' => ['backports/2.3.0/hash/dig', 'backports/2.3.0/struct/dig'],
105
+ '2.3.0/hash/dig' => ['backports/2.3.0/array/dig', 'backports/2.3.0/struct/dig'],
106
+ '2.3.0/struct/dig' => ['backports/2.3.0/array/dig', 'backports/2.3.0/hash/dig']
101
107
  )
102
108
  {
103
109
  :each_with_index => %w[enumerable/detect enumerable/find enumerable/find_all enumerable/select enumerable/to_a],
@@ -113,9 +119,11 @@ OLD_IGNORE_IN_18 = %w[
113
119
  1.9.3/string/byteslice
114
120
  1.8.7/proc/yield
115
121
  1.9.1/proc/case_compare
122
+ 2.4.0/string/match
123
+ 2.4.0/regexp/match
116
124
  ]
117
- # These **new** specs cause actual errors while loading in 1.8:
118
- IGNORE_IN_18 = %w[
125
+ # These **new** specs cause actual errors while loading in 1.9:
126
+ IGNORE_IN_19 = %w[
119
127
  2.1.0/enumerable/to_h
120
128
  2.1.0/array/to_h
121
129
  2.1.0/module/include
@@ -127,9 +135,9 @@ def mspec_cmds(pattern, spec_folder, action='ci')
127
135
  next if path =~ /stdlib/
128
136
  next if version <= RUBY_VERSION
129
137
  version_path = "#{version}/#{path}"
130
- if RUBY_VERSION <= '2.0.0'
138
+ if RUBY_VERSION < '2.0.0'
131
139
  next if OLD_IGNORE_IN_18.include? version_path if RUBY_VERSION < '1.9'
132
- next if IGNORE_IN_18.include? version_path
140
+ next if IGNORE_IN_19.include? version_path
133
141
  next if spec_folder != 'frozen_old_spec' && version <= '2.0.0' # Don't run new specs for pre 2.0 features & ruby
134
142
  end
135
143
  deps = [*DEPENDENCIES[version_path]].map{|p| "-r #{p}"}.join(' ')
@@ -1,4 +1,3 @@
1
- require "backports/tools"
2
1
  require "backports/version"
3
2
  require "backports/2.1"
4
3
  require "backports/rails"
@@ -1,4 +1,4 @@
1
1
  # require this file to load all the backports of Ruby 1.8.7
2
- require "backports/tools"
2
+ require "backports/tools/require_relative_dir"
3
3
  require "backports/std_lib"
4
4
  Backports.require_relative_dir
@@ -1,4 +1,4 @@
1
- require 'backports/tools'
1
+ require 'backports/tools/alias_method'
2
2
 
3
3
  class << ARGF
4
4
  Backports.alias_method self, :lines, :each_line
@@ -1,4 +1,4 @@
1
- require 'backports/tools'
1
+ require 'backports/tools/make_block_optional'
2
2
 
3
3
  class << Dir
4
4
  begin
@@ -117,7 +117,8 @@ end
117
117
  # * #to_s
118
118
  # * #inspect
119
119
  #
120
- Backports.suppress_verbose_warnings do
120
+ require 'backports/tools/suppress_verbose_warnings' # *** Backports addition
121
+ Backports.suppress_verbose_warnings do # *** Backports addition
121
122
  class Matrix
122
123
  include Enumerable
123
124
  include ExceptionForMatrix
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,7 @@
1
+ unless Kernel.method_defined? :itself
2
+ module Kernel
3
+ def itself
4
+ self
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,9 @@
1
+ unless Method.method_defined? :curry
2
+ require 'backports/1.9.1/proc/curry'
3
+
4
+ class Method
5
+ def curry(argc = nil)
6
+ to_proc.curry(argc)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,29 @@
1
+ # Adapted from CRuby
2
+
3
+ unless String.method_defined? :unicode_normalize
4
+ if (Regexp.compile("[\u{11100}-\u{11102}]") rescue false)
5
+ class String
6
+ def unicode_normalize(form = :nfc)
7
+ require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
8
+ ## The following line can be uncommented to avoid repeated checking for
9
+ ## UnicodeNormalize. However, tests didn't show any noticeable speedup
10
+ ## when doing this. This comment also applies to the commented out lines
11
+ ## in String#unicode_normalize! and String#unicode_normalized?.
12
+ # String.send(:define_method, :unicode_normalize, ->(form = :nfc) { UnicodeNormalize.normalize(self, form) } )
13
+ UnicodeNormalize.normalize(self, form)
14
+ end
15
+
16
+ def unicode_normalize!(form = :nfc)
17
+ require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
18
+ # String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } )
19
+ replace(unicode_normalize(form))
20
+ end
21
+
22
+ def unicode_normalized?(form = :nfc)
23
+ require 'backports/tools/normalize.rb' unless defined? UnicodeNormalize
24
+ # String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } )
25
+ UnicodeNormalize.normalized?(self, form)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,32 @@
1
+ unless Array.method_defined? :bsearch_index
2
+ class Array
3
+ def bsearch_index
4
+ return to_enum(__method__) unless block_given?
5
+ from = 0
6
+ to = size - 1
7
+ satisfied = nil
8
+ while from <= to do
9
+ midpoint = (from + to).div(2)
10
+ result = yield(self[midpoint])
11
+ case result
12
+ when Numeric
13
+ return midpoint if result == 0
14
+ result = result < 0
15
+ when true
16
+ satisfied = midpoint
17
+ when nil, false
18
+ # nothing to do
19
+ else
20
+ raise TypeError, "wrong argument type #{result.class} (must be numeric, true, false or nil)"
21
+ end
22
+
23
+ if result
24
+ to = midpoint - 1
25
+ else
26
+ from = midpoint + 1
27
+ end
28
+ end
29
+ satisfied
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ unless Array.method_defined? :dig
2
+ class Array
3
+ def dig(index, *rest)
4
+ val = self[index]
5
+ return val if rest.empty? || val == nil
6
+ raise TypeError, "#{val.class} does not have #dig method" unless val.respond_to? :dig
7
+ val.dig(*rest)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,27 @@
1
+ unless Enumerable.method_defined? :chunk_while
2
+ require 'backports/tools/arguments'
3
+ require 'backports/1.9.1/enumerator/new'
4
+
5
+ module Enumerable
6
+ def chunk_while(&block)
7
+ raise ArgumentError, 'tried to create Proc object without a block' unless block
8
+ enum = self
9
+ Enumerator.new do |y|
10
+ acc = []
11
+ prev = Backports::Undefined
12
+ enum.each do |*elem|
13
+ elem = elem.first if elem.length == 1
14
+ unless prev == Backports::Undefined
15
+ unless block.call(prev, elem)
16
+ y.yield acc
17
+ acc = []
18
+ end
19
+ end
20
+ acc << elem
21
+ prev = elem
22
+ end
23
+ y.yield acc unless acc.empty?
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ unless Enumerable.method_defined? :grep_v
2
+ require 'backports/1.9.2/enumerable/each_entry'
3
+
4
+ module Enumerable
5
+ def grep_v(pattern)
6
+ if block_given?
7
+ acc = []
8
+ each_entry do |v|
9
+ acc << yield(v) unless pattern === v
10
+ end
11
+ acc
12
+ else
13
+ reject {|v| pattern === v }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ require 'backports/tools/require_relative_dir'
2
+
3
+ Backports.require_relative_dir
@@ -0,0 +1,10 @@
1
+ unless Hash.method_defined? :dig
2
+ class Hash
3
+ def dig(key, *rest)
4
+ val = self[key]
5
+ return val if rest.empty? || val == nil
6
+ raise TypeError, "#{val.class} does not have #dig method" unless val.respond_to? :dig
7
+ val.dig(*rest)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ unless Hash.method_defined? :fetch_values
2
+ class Hash
3
+ def fetch_values(*keys, &block)
4
+ keys.map do |k|
5
+ fetch(k, &block)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ unless Hash.method_defined? :>
2
+ require 'backports/tools/arguments'
3
+ require 'backports/2.3.0/hash/lt'
4
+ class Hash
5
+ def >(hash)
6
+ hash = Backports.coerce_to_hash(hash)
7
+ hash < self
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ unless Hash.method_defined? :>=
2
+ require 'backports/tools/arguments'
3
+ require 'backports/2.3.0/hash/lte'
4
+ class Hash
5
+ def >=(hash)
6
+ hash = Backports.coerce_to_hash(hash)
7
+ hash <= self
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ unless Hash.method_defined? :<
2
+ require 'backports/tools/arguments'
3
+ class Hash
4
+ def <(hash)
5
+ hash = Backports.coerce_to_hash(hash)
6
+ return false unless size < hash.size
7
+ each do |k, v|
8
+ v2 = hash.fetch(k){ return false }
9
+ return false unless v2 == v
10
+ end
11
+ true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ unless Hash.method_defined? :<=
2
+ require 'backports/tools/arguments'
3
+ class Hash
4
+ def <=(hash)
5
+ hash = Backports.coerce_to_hash(hash)
6
+ return false unless size <= hash.size
7
+ each do |k, v|
8
+ v2 = hash.fetch(k){ return false }
9
+ return false unless v2 == v
10
+ end
11
+ true
12
+ end
13
+ end
14
+ end