backports 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,30 @@
1
1
  = Packable --- History
2
2
 
3
+ == Version 2.5.0 - March 25th, 2012
4
+
5
+ * Added some features of 1.9.3:
6
+ * IO::NULL
7
+ * IO#advise
8
+ * String#byteslice
9
+ * String#prepend
10
+
11
+ == Version 2.4.0 - March 24th, 2012
12
+
13
+ * Add backporting for libraries
14
+
15
+ * Bring libraries up to date:
16
+ * Matrix
17
+ * Prime
18
+ * Set
19
+
20
+ * Added some features of 1.9.3:
21
+ * IO.write, IO.binwrite
22
+
23
+ * Add forcing backports (must be required explicitly):
24
+ * Hash#select (returns a Hash instead of an Array)
25
+ * Enumerable / Array#map (returns an enumerator when called without a block)
26
+ * String#length, size (for UTF-8 support)
27
+
3
28
  == Version 2.3.0 - May 13th, 2011
4
29
 
5
30
  * Added Enumerator::Yielder#<<
@@ -1,6 +1,6 @@
1
1
  = Backports Library
2
2
 
3
- * Yearning to use some of the new cool features in 1.9.2 while using 1.8.x?
3
+ * Yearning to use some of the new cool features in 1.9.3 while using 1.8.6?
4
4
  * One of your client is stuck with Ruby 1.8.6 but you want to use a gem using some features of 1.8.7?
5
5
  * Can't remember if you can use Array#sample or String#each_char on a friend's box?
6
6
 
@@ -10,7 +10,7 @@ The goal of 'backports' is to make it easier to write ruby code that runs across
10
10
 
11
11
  require 'backports'
12
12
 
13
- This will bring in all the features of 1.8.7 (for Ruby 1.8.6) and many features of Ruby 1.9.1 (for Ruby 1.8.x) and Ruby 1.9.2 (for all earlier versions)!
13
+ This will bring in all the features of 1.8.7 (for Ruby 1.8.6) and many features of Ruby 1.9.1 (for Ruby 1.8.x), Ruby 1.9.2 and Ruby 1.9.3 (for all earlier versions)!
14
14
 
15
15
  +Note+: Although I am a Ruby committer, this gem is a personal project and is not endorsed by ruby-core.
16
16
 
@@ -40,7 +40,7 @@ To use:
40
40
  require 'rubygems'
41
41
  require 'backports' # or a subset, see next section
42
42
 
43
- Compatible with Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2, JRuby and Rubinius.
43
+ Compatible with Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2, 1.9.3, JRuby and Rubinius.
44
44
 
45
45
  = Complete List of backports
46
46
 
@@ -180,8 +180,14 @@ To include all Ruby backports but not those of Rails, <tt>require "backports/1.9
180
180
 
181
181
  Some features of Ruby 1.9.3 have been backported:
182
182
 
183
+ * File
184
+ * +NULL+
183
185
  * IO
186
+ * +advise+ (acts as a noop)
184
187
  * +write+, +binwrite+
188
+ * String
189
+ * +byteslice+
190
+ * +prepend+
185
191
 
186
192
  == Rails
187
193
 
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :build:
3
3
  :major: 2
4
- :minor: 4
4
+ :minor: 5
5
5
  :patch: 0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{backports}
8
- s.version = "2.4.0"
8
+ s.version = "2.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marc-Andr\303\251 Lafortune"]
12
- s.date = %q{2012-03-24}
12
+ s.date = %q{2012-03-25}
13
13
  s.description = %q{ Essential backports that enable some of the really nice features of ruby 1.8.7, ruby 1.9 and rails from ruby 1.8.6 and earlier.
14
14
  }
15
15
  s.email = %q{github@marc-andre.ca}
@@ -96,7 +96,9 @@ Gem::Specification.new do |s|
96
96
  "lib/backports/1.9.2/stdlib/matrix/lup_decomposition.rb",
97
97
  "lib/backports/1.9.2/stdlib/set.rb",
98
98
  "lib/backports/1.9.3.rb",
99
+ "lib/backports/1.9.3/file.rb",
99
100
  "lib/backports/1.9.3/io.rb",
101
+ "lib/backports/1.9.3/string.rb",
100
102
  "lib/backports/1.9.rb",
101
103
  "lib/backports/basic_object.rb",
102
104
  "lib/backports/force/array_map.rb",
@@ -0,0 +1,12 @@
1
+ class File
2
+ NULL = case RUBY_PLATFORM
3
+ when /mswin/i
4
+ 'NUL'
5
+ when /amiga/i
6
+ 'NIL:'
7
+ when /openvms/i
8
+ 'NL:'
9
+ else
10
+ '/dev/null'
11
+ end unless const_defined?(:NULL)
12
+ end
@@ -1,3 +1,23 @@
1
+ class IO
2
+ # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-i-advise]
3
+ # We're only for a platform not implementing advise, so we return nil.
4
+ def advise(advice, offset=0, len=0)
5
+ case advice
6
+ when :normal,
7
+ :sequential,
8
+ :random,
9
+ :willneed,
10
+ :dontneed,
11
+ :noreuse
12
+ return nil
13
+ when Symbol
14
+ raise NotImplementedError, "Unsupported advice #{advice}"
15
+ else
16
+ raise TypeError, "advice must be a Symbol"
17
+ end
18
+ end unless method_defined? :advise
19
+ end
20
+
1
21
  class << IO
2
22
  # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/IO.html#method-c-write]
3
23
  def write(name, string, offset = nil, options = Backports::Undefined)
@@ -0,0 +1,39 @@
1
+ class String
2
+ # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/String.html#byteslice]
3
+ def byteslice(start, len = Backports::Undefined)
4
+ # Argument parsing & checking
5
+ if Backports::Undefined == len
6
+ if start.is_a?(Range)
7
+ range = start
8
+ start = Backports.coerce_to_int(range.begin)
9
+ start += bytesize if start < 0
10
+ last = Backports.coerce_to_int(range.end)
11
+ last += bytesize if last < 0
12
+ last += 1 unless range.exclude_end?
13
+ len = last - start
14
+ else
15
+ start = Backports.coerce_to_int(start)
16
+ start += bytesize if start < 0
17
+ len = 1
18
+ return if start >= bytesize
19
+ end
20
+ else
21
+ start = Backports.coerce_to_int(start)
22
+ start += bytesize if start < 0
23
+ len = Backports.coerce_to_int(len)
24
+ return if len < 0
25
+ end
26
+ return if start < 0 || start > bytesize
27
+ len = 0 if len < 0
28
+ # Actual implementation:
29
+ str = unpack("@#{start}a#{len}").first
30
+ str = dup.replace(str) unless self.instance_of?(String) # Must return subclass
31
+ str.force_encoding(encoding)
32
+ end unless method_defined? :byteslice
33
+
34
+ # Standard in Ruby 1.9.3 See official documentation[http://ruby-doc.org/core-1.9.3/String.html#method-i-prepend]
35
+ def prepend(other_str)
36
+ replace Backports.coerce_to_str(other_str) + self
37
+ self
38
+ end unless method_defined? :prepend
39
+ end
@@ -211,6 +211,10 @@ module Backports
211
211
  coerce_to(obj, Array, :to_ary)
212
212
  end
213
213
 
214
+ def self.coerce_to_str(obj)
215
+ coerce_to(obj, String, :to_str)
216
+ end
217
+
214
218
  def self.try_convert(obj, cls, meth)
215
219
  return obj if obj.kind_of?(cls)
216
220
  return nil unless obj.respond_to?(meth)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backports
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 2.4.0
10
+ version: 2.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Marc-Andr\xC3\xA9 Lafortune"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-24 00:00:00 -04:00
18
+ date: 2012-03-25 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -107,7 +107,9 @@ files:
107
107
  - lib/backports/1.9.2/stdlib/matrix/lup_decomposition.rb
108
108
  - lib/backports/1.9.2/stdlib/set.rb
109
109
  - lib/backports/1.9.3.rb
110
+ - lib/backports/1.9.3/file.rb
110
111
  - lib/backports/1.9.3/io.rb
112
+ - lib/backports/1.9.3/string.rb
111
113
  - lib/backports/1.9.rb
112
114
  - lib/backports/basic_object.rb
113
115
  - lib/backports/force/array_map.rb