storable 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +6 -0
- data/lib/storable.rb +28 -7
- data/storable.gemspec +1 -1
- metadata +2 -2
data/CHANGES.txt
CHANGED
@@ -2,6 +2,12 @@ STORABLE, CHANGES
|
|
2
2
|
|
3
3
|
* TODO: field_types and field_names go out of order when defining some fields with types and others not. The quick fix is to define fields with no type at the end
|
4
4
|
|
5
|
+
|
6
|
+
#### 0.6.5 (2010-03-23) #############################
|
7
|
+
|
8
|
+
* ADDED: Use Yajl if it's available.
|
9
|
+
|
10
|
+
|
5
11
|
#### 0.6.4 (2010-03-10) #############################
|
6
12
|
|
7
13
|
* FIXED: Don't pull the first value out of an array if there is only one element.
|
data/lib/storable.rb
CHANGED
@@ -6,12 +6,20 @@
|
|
6
6
|
|
7
7
|
USE_ORDERED_HASH = (RUBY_VERSION =~ /^1.9/).nil?
|
8
8
|
|
9
|
-
begin
|
10
|
-
require '
|
9
|
+
YAJL_LOADED = begin
|
10
|
+
require 'yajl'
|
11
|
+
true
|
11
12
|
rescue LoadError
|
12
|
-
|
13
|
+
false
|
13
14
|
end
|
14
|
-
|
15
|
+
|
16
|
+
JSON_LOADED = begin
|
17
|
+
require 'json' unless YAJL_LOADED
|
18
|
+
true
|
19
|
+
rescue LoadError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
15
23
|
require 'yaml'
|
16
24
|
require 'fileutils'
|
17
25
|
require 'time'
|
@@ -40,7 +48,7 @@ class Storable
|
|
40
48
|
|
41
49
|
require 'storable/orderedhash' if USE_ORDERED_HASH
|
42
50
|
unless defined?(SUPPORTED_FORMATS) # We can assume all are defined
|
43
|
-
VERSION = "0.6.
|
51
|
+
VERSION = "0.6.5"
|
44
52
|
NICE_TIME_FORMAT = "%Y-%m-%d@%H:%M:%S".freeze
|
45
53
|
SUPPORTED_FORMATS = [:tsv, :csv, :yaml, :json, :s, :string].freeze
|
46
54
|
end
|
@@ -219,7 +227,14 @@ class Storable
|
|
219
227
|
end
|
220
228
|
|
221
229
|
def to_json(*from, &blk)
|
222
|
-
to_hash
|
230
|
+
hash = to_hash
|
231
|
+
if YAJL_LOADED
|
232
|
+
Yajl::Encoder.encode(hash)
|
233
|
+
elsif JSON_LOADED
|
234
|
+
hash.to_json(*from, &blk)
|
235
|
+
else
|
236
|
+
raise "no JSON parser loaded"
|
237
|
+
end
|
223
238
|
end
|
224
239
|
|
225
240
|
def to_yaml(*from, &blk)
|
@@ -247,7 +262,13 @@ class Storable
|
|
247
262
|
# +from+ a YAML String or Array (split into by line).
|
248
263
|
def self.from_json(*from)
|
249
264
|
from_str = [from].flatten.compact.join('')
|
250
|
-
|
265
|
+
if YAJL_LOADED
|
266
|
+
tmp = Yajl::Parser.parse(from_str)
|
267
|
+
elsif JSON_LOADED
|
268
|
+
tmp = JSON::load(from_str)
|
269
|
+
else
|
270
|
+
raise "JSON parser not loaded"
|
271
|
+
end
|
251
272
|
hash_sym = tmp.keys.inject({}) do |hash, key|
|
252
273
|
hash[key.to_sym] = tmp[key]
|
253
274
|
hash
|
data/storable.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = "storable"
|
3
3
|
s.rubyforge_project = "storable"
|
4
|
-
s.version = "0.6.
|
4
|
+
s.version = "0.6.5"
|
5
5
|
s.summary = "Storable: Marshal Ruby classes into and out of multiple formats (yaml, json, csv, tsv)"
|
6
6
|
s.description = s.summary
|
7
7
|
s.author = "Delano Mandelbaum"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-23 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|