psych 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,28 @@
1
- === 1.0.0 / 2009-09-26
1
+ Thu Jun 9 10:57:03 2011 Aaron Patterson <aaron@tenderlovemaking.com>
2
2
 
3
- * Birthday!
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!
@@ -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 it's YAML parsing and emitting capabilities. In addition to wrapping
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
 
@@ -304,6 +304,7 @@ static VALUE parse(VALUE self, VALUE yaml)
304
304
  done = 1;
305
305
  break;
306
306
  }
307
+ yaml_event_delete(&event);
307
308
  }
308
309
 
309
310
  return self;
@@ -90,7 +90,7 @@ require 'psych/json'
90
90
 
91
91
  module Psych
92
92
  # The version is Psych you're using
93
- VERSION = '1.1.1'
93
+ VERSION = '1.2.0'
94
94
 
95
95
  # The version of libyaml Psych is using
96
96
  LIBYAML_VERSION = Psych.libyaml_version.join '.'
@@ -31,7 +31,7 @@ module Psych
31
31
  # doc = Psych::Nodes::Document.new
32
32
  # seq = Psych::Nodes::Sequence.new
33
33
  # scalar = Psych::Nodes::Scalar.new('foo')
34
- #
34
+ #
35
35
  # # Build up our tree
36
36
  # stream.children << doc
37
37
  # doc.children << seq
@@ -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
- o.children.each_slice(2) { |k,v|
189
- key = accept(k)
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
- hash
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.class}"
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
- register(o, @emitter.start_mapping(nil, nil, true, Psych::Nodes::Mapping::BLOCK))
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
@@ -2,16 +2,35 @@ require 'psych/helper'
2
2
 
3
3
  module Psych
4
4
  class TestClass < TestCase
5
- def test_cycle
5
+ module Foo
6
+ end
7
+
8
+ def test_cycle_anonymous_class
6
9
  assert_raises(::TypeError) do
7
- assert_cycle(TestClass)
10
+ assert_cycle(Class.new)
8
11
  end
9
12
  end
10
13
 
11
- def test_dump
14
+ def test_cycle_anonymous_module
12
15
  assert_raises(::TypeError) do
13
- Psych.dump TestClass
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
@@ -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)
@@ -10,7 +10,7 @@ module Psych
10
10
  ---
11
11
  - ~
12
12
  - null
13
- -
13
+ -
14
14
  - Null
15
15
  - NULL
16
16
  eoyml
@@ -39,7 +39,7 @@ module Psych
39
39
 
40
40
  def test_load
41
41
  obj = Psych.load(<<-eoyml)
42
- --- !ruby/struct:PsychStructWithIvar
42
+ --- !ruby/struct:PsychStructWithIvar
43
43
  :foo: bar
44
44
  :@bar: hello
45
45
  eoyml
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.1.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-05-13 00:00:00.000000000 Z
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: &2153250500 !ruby/object:Gem::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: *2153250500
24
+ version_requirements: *2152339440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &2153250040 !ruby/object:Gem::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.1
32
+ version: 2.9.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153250040
35
+ version_requirements: *2152316780
36
36
  description: ! 'Psych is a YAML parser and emitter. Psych leverages libyaml[http://libyaml.org]
37
37
 
38
- for it''s YAML parsing and emitting capabilities. In addition to wrapping
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.2
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