data-writer 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/data-writer.gemspec +2 -2
- data/lib/data-writer.rb +15 -8
- metadata +2 -2
data/README.md
CHANGED
data/data-writer.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'data-writer'
|
3
|
-
s.version = '0.9.
|
4
|
-
s.date = '2012-07-
|
3
|
+
s.version = '0.9.2'
|
4
|
+
s.date = '2012-07-30'
|
5
5
|
s.summary = "Allows you to write to DATA"
|
6
6
|
s.description = "Normally you can only read from DATA but with data-writer you can also write to it. This allows you to easily persist data in a source file."
|
7
7
|
s.authors = ["Kalle Lindstrom"]
|
data/lib/data-writer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
|
2
3
|
class DATAWriter
|
3
4
|
|
@@ -43,11 +44,13 @@ class DATAWriter
|
|
43
44
|
#
|
44
45
|
def self.get_valid_string_mode(mode)
|
45
46
|
if mode =~ /w/
|
46
|
-
clear_end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
clear_end # truncate after __END__ only.
|
48
|
+
if mode.include?("+")
|
49
|
+
mode.sub!("w", "r")
|
50
|
+
else
|
51
|
+
mode.sub!("w", "r+")
|
52
|
+
end
|
53
|
+
mode
|
51
54
|
else
|
52
55
|
mode
|
53
56
|
end
|
@@ -79,15 +82,19 @@ class DATAWriter
|
|
79
82
|
# Helper method to create a file that works in both 1.8 and 1.9 and different implementations.
|
80
83
|
#
|
81
84
|
def self.create_file(path, mode_string, opt = {})
|
85
|
+
ruby = RUBY_VERSION[/\d\.\d\.\d/]
|
86
|
+
|
82
87
|
if RUBY_PLATFORM =~ /java/i
|
83
|
-
if
|
84
|
-
|
88
|
+
if ruby >= "1.9.3"
|
89
|
+
opt = {:encoding => __ENCODING__}.merge(opt) # Make sure the IO encoding is the same as the source encoding.
|
90
|
+
File.new(path, mode_string, opt) # Only JRuby 1.7 seem to implement this method the 1.9 way.
|
85
91
|
else
|
86
92
|
File.new(path, mode_string)
|
87
93
|
end
|
88
94
|
|
89
95
|
else
|
90
|
-
if
|
96
|
+
if ruby >= "1.9.0"
|
97
|
+
opt = {:encoding => __ENCODING__}.merge(opt)
|
91
98
|
File.new(path, mode_string, opt)
|
92
99
|
else
|
93
100
|
File.new(path, mode_string)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data-writer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|