psych 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +27 -2
- data/README.rdoc +1 -1
- data/ext/psych/parser.c +1 -0
- data/lib/psych.rb +1 -1
- data/lib/psych/nodes.rb +1 -1
- data/lib/psych/visitors/to_ruby.rb +32 -22
- data/lib/psych/visitors/yaml_tree.rb +11 -2
- data/test/psych/test_class.rb +23 -4
- data/test/psych/test_hash.rb +14 -0
- data/test/psych/test_null.rb +1 -1
- data/test/psych/test_struct.rb +1 -1
- metadata +9 -9
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
-
|
1
|
+
Thu Jun 9 10:57:03 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
2
|
|
3
|
-
*
|
3
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: Hash subclasses can be read
|
4
|
+
from YAML files.
|
5
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: Hash subclasses can be
|
6
|
+
dumped to YAML files.
|
7
|
+
* test/psych/test_hash.rb: corresponding test.
|
8
|
+
|
9
|
+
Thu Jun 9 09:18:51 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
10
|
+
|
11
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: Ruby modules can be loaded
|
12
|
+
from YAML files.
|
13
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby modules can be
|
14
|
+
dumped to YAML files.
|
15
|
+
* test/psych/test_class.rb: corresponding test.
|
16
|
+
|
17
|
+
Thu Jun 9 09:05:04 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
18
|
+
|
19
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: Ruby classes can be loaded
|
20
|
+
from YAML files.
|
21
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: Ruby classes can be
|
22
|
+
dumped to YAML files.
|
23
|
+
* test/psych/test_class.rb: corresponding test.
|
24
|
+
|
25
|
+
Mon Jun 6 09:39:43 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
26
|
+
|
27
|
+
* ext/psych/parser.c (parse): release event objects to plug memory
|
28
|
+
leak. Thanks Mark J. Titorenko!
|
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
== Description
|
6
6
|
|
7
7
|
Psych is a YAML parser and emitter. Psych leverages libyaml[http://libyaml.org]
|
8
|
-
for
|
8
|
+
for its YAML parsing and emitting capabilities. In addition to wrapping
|
9
9
|
libyaml, Psych also knows how to serialize and de-serialize most Ruby objects
|
10
10
|
to and from the YAML format.
|
11
11
|
|
data/ext/psych/parser.c
CHANGED
data/lib/psych.rb
CHANGED
data/lib/psych/nodes.rb
CHANGED
@@ -57,6 +57,8 @@ module Psych
|
|
57
57
|
Complex(o.value)
|
58
58
|
when "!ruby/object:Rational"
|
59
59
|
Rational(o.value)
|
60
|
+
when "!ruby/class", "!ruby/module"
|
61
|
+
resolve_class o.value
|
60
62
|
when "tag:yaml.org,2002:float", "!float"
|
61
63
|
Float(@ss.tokenize(o.value))
|
62
64
|
when "!ruby/regexp"
|
@@ -118,6 +120,7 @@ module Psych
|
|
118
120
|
|
119
121
|
def visit_Psych_Nodes_Mapping o
|
120
122
|
return revive(Psych.load_tags[o.tag], o) if Psych.load_tags[o.tag]
|
123
|
+
return revive_hash({}, o) unless o.tag
|
121
124
|
|
122
125
|
case o.tag
|
123
126
|
when '!str', 'tag:yaml.org,2002:str'
|
@@ -181,30 +184,12 @@ module Psych
|
|
181
184
|
obj = revive((resolve_class(name) || Object), o)
|
182
185
|
@st[o.anchor] = obj if o.anchor
|
183
186
|
obj
|
184
|
-
else
|
185
|
-
hash = {}
|
186
|
-
@st[o.anchor] = hash if o.anchor
|
187
187
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
if key == '<<'
|
192
|
-
case v
|
193
|
-
when Nodes::Alias
|
194
|
-
hash.merge! accept(v)
|
195
|
-
when Nodes::Sequence
|
196
|
-
accept(v).reverse_each do |value|
|
197
|
-
hash.merge! value
|
198
|
-
end
|
199
|
-
else
|
200
|
-
hash[key] = accept(v)
|
201
|
-
end
|
202
|
-
else
|
203
|
-
hash[key] = accept(v)
|
204
|
-
end
|
188
|
+
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
|
189
|
+
revive_hash resolve_class($1).new, o
|
205
190
|
|
206
|
-
|
207
|
-
|
191
|
+
else
|
192
|
+
revive_hash({}, o)
|
208
193
|
end
|
209
194
|
end
|
210
195
|
|
@@ -221,6 +206,31 @@ module Psych
|
|
221
206
|
end
|
222
207
|
|
223
208
|
private
|
209
|
+
def revive_hash hash, o
|
210
|
+
@st[o.anchor] = hash if o.anchor
|
211
|
+
|
212
|
+
o.children.each_slice(2) { |k,v|
|
213
|
+
key = accept(k)
|
214
|
+
|
215
|
+
if key == '<<'
|
216
|
+
case v
|
217
|
+
when Nodes::Alias
|
218
|
+
hash.merge! accept(v)
|
219
|
+
when Nodes::Sequence
|
220
|
+
accept(v).reverse_each do |value|
|
221
|
+
hash.merge! value
|
222
|
+
end
|
223
|
+
else
|
224
|
+
hash[key] = accept(v)
|
225
|
+
end
|
226
|
+
else
|
227
|
+
hash[key] = accept(v)
|
228
|
+
end
|
229
|
+
|
230
|
+
}
|
231
|
+
hash
|
232
|
+
end
|
233
|
+
|
224
234
|
def revive klass, node
|
225
235
|
s = klass.allocate
|
226
236
|
h = Hash[*node.children.map { |c| accept c }]
|
@@ -246,8 +246,14 @@ module Psych
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
|
+
def visit_Module o
|
250
|
+
raise TypeError, "can't dump anonymous module: #{o}" unless o.name
|
251
|
+
@emitter.scalar o.name, nil, '!ruby/module', false, false, Nodes::Scalar::SINGLE_QUOTED
|
252
|
+
end
|
253
|
+
|
249
254
|
def visit_Class o
|
250
|
-
raise TypeError, "can't dump anonymous class #{o
|
255
|
+
raise TypeError, "can't dump anonymous class: #{o}" unless o.name
|
256
|
+
@emitter.scalar o.name, nil, '!ruby/class', false, false, Nodes::Scalar::SINGLE_QUOTED
|
251
257
|
end
|
252
258
|
|
253
259
|
def visit_Range o
|
@@ -259,7 +265,10 @@ module Psych
|
|
259
265
|
end
|
260
266
|
|
261
267
|
def visit_Hash o
|
262
|
-
|
268
|
+
tag = o.class == ::Hash ? nil : "!ruby/hash:#{o.class}"
|
269
|
+
implicit = !tag
|
270
|
+
|
271
|
+
register(o, @emitter.start_mapping(nil, tag, implicit, Psych::Nodes::Mapping::BLOCK))
|
263
272
|
|
264
273
|
o.each do |k,v|
|
265
274
|
accept k
|
data/test/psych/test_class.rb
CHANGED
@@ -2,16 +2,35 @@ require 'psych/helper'
|
|
2
2
|
|
3
3
|
module Psych
|
4
4
|
class TestClass < TestCase
|
5
|
-
|
5
|
+
module Foo
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_cycle_anonymous_class
|
6
9
|
assert_raises(::TypeError) do
|
7
|
-
assert_cycle(
|
10
|
+
assert_cycle(Class.new)
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
|
-
def
|
14
|
+
def test_cycle_anonymous_module
|
12
15
|
assert_raises(::TypeError) do
|
13
|
-
|
16
|
+
assert_cycle(Module.new)
|
14
17
|
end
|
15
18
|
end
|
19
|
+
|
20
|
+
def test_cycle
|
21
|
+
assert_cycle(TestClass)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_dump
|
25
|
+
Psych.dump TestClass
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_cycle_module
|
29
|
+
assert_cycle(Foo)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_dump_module
|
33
|
+
Psych.dump Foo
|
34
|
+
end
|
16
35
|
end
|
17
36
|
end
|
data/test/psych/test_hash.rb
CHANGED
@@ -2,11 +2,25 @@ require 'psych/helper'
|
|
2
2
|
|
3
3
|
module Psych
|
4
4
|
class TestHash < TestCase
|
5
|
+
class X < Hash
|
6
|
+
end
|
7
|
+
|
5
8
|
def setup
|
6
9
|
super
|
7
10
|
@hash = { :a => 'b' }
|
8
11
|
end
|
9
12
|
|
13
|
+
def test_empty_subclass
|
14
|
+
assert_match "!ruby/hash:#{X}", Psych.dump(X.new)
|
15
|
+
x = Psych.load Psych.dump X.new
|
16
|
+
assert_equal X, x.class
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_map
|
20
|
+
x = Psych.load "--- !map:#{X} { }\n"
|
21
|
+
assert_equal X, x.class
|
22
|
+
end
|
23
|
+
|
10
24
|
def test_self_referential
|
11
25
|
@hash['self'] = @hash
|
12
26
|
assert_cycle(@hash)
|
data/test/psych/test_null.rb
CHANGED
data/test/psych/test_struct.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psych
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152339440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 0.4.1
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152339440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152316780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 2.9.
|
32
|
+
version: 2.9.4
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152316780
|
36
36
|
description: ! 'Psych is a YAML parser and emitter. Psych leverages libyaml[http://libyaml.org]
|
37
37
|
|
38
|
-
for
|
38
|
+
for its YAML parsing and emitting capabilities. In addition to wrapping
|
39
39
|
|
40
40
|
libyaml, Psych also knows how to serialize and de-serialize most Ruby objects
|
41
41
|
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project: psych
|
164
|
-
rubygems_version: 1.8.
|
164
|
+
rubygems_version: 1.8.5
|
165
165
|
signing_key:
|
166
166
|
specification_version: 3
|
167
167
|
summary: Psych is a YAML parser and emitter
|