psych 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +11 -0
- data/ext/psych/emitter.c +25 -4
- data/ext/psych/extconf.rb +2 -2
- data/lib/psych.rb +1 -1
- data/lib/psych/handler.rb +15 -0
- data/lib/psych/visitors/emitter.rb +11 -4
- data/lib/psych/visitors/to_ruby.rb +1 -0
- data/lib/psych/visitors/yaml_tree.rb +1 -1
- data/test/psych/test_alias_and_anchor.rb +70 -0
- metadata +2 -2
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
Thu Jul 19 09:33:46 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
|
+
|
3
|
+
* ext/psych/emitter.c (initialize): allow a configuration object to be
|
4
|
+
passed to the constructor so that mutation isn't required after
|
5
|
+
instantiation.
|
6
|
+
|
7
|
+
* ext/psych/lib/psych/handler.rb: add configuration object
|
8
|
+
|
9
|
+
* ext/psych/lib/psych/visitors/emitter.rb: use configuration object if
|
10
|
+
extra configuration is present.
|
11
|
+
|
1
12
|
Fri May 18 01:28:21 2012 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
13
|
|
3
14
|
* ext/psych/parser.c (transcode_string): fix encoding index names.
|
data/ext/psych/emitter.c
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
VALUE cPsychEmitter;
|
4
4
|
static ID id_write;
|
5
|
+
static ID id_line_width;
|
6
|
+
static ID id_indentation;
|
7
|
+
static ID id_canonical;
|
5
8
|
|
6
9
|
static void emit(yaml_emitter_t * emitter, yaml_event_t * event)
|
7
10
|
{
|
@@ -39,15 +42,30 @@ static VALUE allocate(VALUE klass)
|
|
39
42
|
return Data_Wrap_Struct(klass, 0, dealloc, emitter);
|
40
43
|
}
|
41
44
|
|
42
|
-
/* call-seq: Psych::Emitter.new(io)
|
45
|
+
/* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
|
43
46
|
*
|
44
47
|
* Create a new Psych::Emitter that writes to +io+.
|
45
48
|
*/
|
46
|
-
static VALUE initialize(VALUE
|
49
|
+
static VALUE initialize(int argc, VALUE *argv, VALUE self)
|
47
50
|
{
|
48
51
|
yaml_emitter_t * emitter;
|
52
|
+
VALUE io, options;
|
53
|
+
VALUE line_width;
|
54
|
+
VALUE indent;
|
55
|
+
VALUE canonical;
|
56
|
+
|
49
57
|
Data_Get_Struct(self, yaml_emitter_t, emitter);
|
50
58
|
|
59
|
+
if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
|
60
|
+
line_width = rb_funcall(options, id_line_width, 0);
|
61
|
+
indent = rb_funcall(options, id_indentation, 0);
|
62
|
+
canonical = rb_funcall(options, id_canonical, 0);
|
63
|
+
|
64
|
+
yaml_emitter_set_width(emitter, NUM2INT(line_width));
|
65
|
+
yaml_emitter_set_indent(emitter, NUM2INT(indent));
|
66
|
+
yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
|
67
|
+
}
|
68
|
+
|
51
69
|
yaml_emitter_set_output(emitter, writer, (void *)io);
|
52
70
|
|
53
71
|
return self;
|
@@ -494,7 +512,7 @@ void Init_psych_emitter()
|
|
494
512
|
|
495
513
|
rb_define_alloc_func(cPsychEmitter, allocate);
|
496
514
|
|
497
|
-
rb_define_method(cPsychEmitter, "initialize", initialize, 1);
|
515
|
+
rb_define_method(cPsychEmitter, "initialize", initialize, -1);
|
498
516
|
rb_define_method(cPsychEmitter, "start_stream", start_stream, 1);
|
499
517
|
rb_define_method(cPsychEmitter, "end_stream", end_stream, 0);
|
500
518
|
rb_define_method(cPsychEmitter, "start_document", start_document, 3);
|
@@ -512,6 +530,9 @@ void Init_psych_emitter()
|
|
512
530
|
rb_define_method(cPsychEmitter, "line_width", line_width, 0);
|
513
531
|
rb_define_method(cPsychEmitter, "line_width=", set_line_width, 1);
|
514
532
|
|
515
|
-
id_write
|
533
|
+
id_write = rb_intern("write");
|
534
|
+
id_line_width = rb_intern("line_width");
|
535
|
+
id_indentation = rb_intern("indentation");
|
536
|
+
id_canonical = rb_intern("canonical");
|
516
537
|
}
|
517
538
|
/* vim: set noet sws=4 sw=4: */
|
data/ext/psych/extconf.rb
CHANGED
@@ -4,8 +4,8 @@ require 'mkmf'
|
|
4
4
|
|
5
5
|
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
|
6
6
|
|
7
|
-
INCLUDEDIR =
|
8
|
-
LIBDIR =
|
7
|
+
INCLUDEDIR = RbConfig::CONFIG['includedir']
|
8
|
+
LIBDIR = RbConfig::CONFIG['libdir']
|
9
9
|
LIB_DIRS = ['/opt/local/lib', '/usr/local/lib', LIBDIR, '/usr/lib']
|
10
10
|
libyaml = dir_config 'libyaml', '/opt/local/include', '/opt/local/lib'
|
11
11
|
|
data/lib/psych.rb
CHANGED
data/lib/psych/handler.rb
CHANGED
@@ -10,6 +10,21 @@ module Psych
|
|
10
10
|
#
|
11
11
|
# See Psych::Parser for more details
|
12
12
|
class Handler
|
13
|
+
###
|
14
|
+
# Configuration options for dumping YAML.
|
15
|
+
class DumperOptions
|
16
|
+
attr_accessor :line_width, :indentation, :canonical
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@line_width = 0
|
20
|
+
@indentation = 2
|
21
|
+
@canonical = false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Default dumping options
|
26
|
+
OPTIONS = DumperOptions.new
|
27
|
+
|
13
28
|
###
|
14
29
|
# Called with +encoding+ when the YAML stream starts. This method is
|
15
30
|
# called once per stream. A stream may contain multiple documents.
|
@@ -2,10 +2,17 @@ module Psych
|
|
2
2
|
module Visitors
|
3
3
|
class Emitter < Psych::Visitors::Visitor
|
4
4
|
def initialize io, options = {}
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
opts = [:indentation, :canonical, :line_width].find_all { |opt|
|
6
|
+
options.key?(opt)
|
7
|
+
}
|
8
|
+
|
9
|
+
if opts.empty?
|
10
|
+
@handler = Psych::Emitter.new io
|
11
|
+
else
|
12
|
+
du = Handler::DumperOptions.new
|
13
|
+
opts.each { |option| du.send :"#{option}=", options[option] }
|
14
|
+
@handler = Psych::Emitter.new io, du
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
def visit_Psych_Nodes_Stream o
|
@@ -254,7 +254,7 @@ module Psych
|
|
254
254
|
maptag = '!ruby/string'
|
255
255
|
maptag << ":#{o.class}" unless o.class == ::String
|
256
256
|
|
257
|
-
@emitter.start_mapping
|
257
|
+
register o, @emitter.start_mapping(nil, maptag, false, Nodes::Mapping::BLOCK)
|
258
258
|
@emitter.scalar 'str', nil, nil, true, false, Nodes::Scalar::ANY
|
259
259
|
@emitter.scalar str, nil, tag, plain, quote, style
|
260
260
|
|
@@ -1,5 +1,13 @@
|
|
1
1
|
require 'psych/helper'
|
2
2
|
|
3
|
+
class ObjectWithInstanceVariables
|
4
|
+
attr_accessor :var1, :var2
|
5
|
+
end
|
6
|
+
|
7
|
+
class SubStringWithInstanceVariables < String
|
8
|
+
attr_accessor :var1
|
9
|
+
end
|
10
|
+
|
3
11
|
module Psych
|
4
12
|
class TestAliasAndAnchor < TestCase
|
5
13
|
def test_mri_compatibility
|
@@ -14,6 +22,40 @@ EOYAML
|
|
14
22
|
result.each {|el| assert_same(result[0], el) }
|
15
23
|
end
|
16
24
|
|
25
|
+
def test_mri_compatibility_object_with_ivars
|
26
|
+
yaml = <<EOYAML
|
27
|
+
---
|
28
|
+
- &id001 !ruby/object:ObjectWithInstanceVariables
|
29
|
+
var1: test1
|
30
|
+
var2: test2
|
31
|
+
- *id001
|
32
|
+
- *id001
|
33
|
+
EOYAML
|
34
|
+
|
35
|
+
result = Psych.load yaml
|
36
|
+
result.each do |el|
|
37
|
+
assert_same(result[0], el)
|
38
|
+
assert_equal('test1', el.var1)
|
39
|
+
assert_equal('test2', el.var2)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_mri_compatibility_substring_with_ivars
|
44
|
+
yaml = <<EOYAML
|
45
|
+
---
|
46
|
+
- &id001 !str:SubStringWithInstanceVariables
|
47
|
+
str: test
|
48
|
+
"@var1": test
|
49
|
+
- *id001
|
50
|
+
- *id001
|
51
|
+
EOYAML
|
52
|
+
result = Psych.load yaml
|
53
|
+
result.each do |el|
|
54
|
+
assert_same(result[0], el)
|
55
|
+
assert_equal('test', el.var1)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
17
59
|
def test_anchor_alias_round_trip
|
18
60
|
o = Object.new
|
19
61
|
original = [o,o,o]
|
@@ -22,5 +64,33 @@ EOYAML
|
|
22
64
|
result = Psych.load yaml
|
23
65
|
result.each {|el| assert_same(result[0], el) }
|
24
66
|
end
|
67
|
+
|
68
|
+
def test_anchor_alias_round_trip_object_with_ivars
|
69
|
+
o = ObjectWithInstanceVariables.new
|
70
|
+
o.var1 = 'test1'
|
71
|
+
o.var2 = 'test2'
|
72
|
+
original = [o,o,o]
|
73
|
+
|
74
|
+
yaml = Psych.dump original
|
75
|
+
result = Psych.load yaml
|
76
|
+
result.each do |el|
|
77
|
+
assert_same(result[0], el)
|
78
|
+
assert_equal('test1', el.var1)
|
79
|
+
assert_equal('test2', el.var2)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_anchor_alias_round_trip_substring_with_ivars
|
84
|
+
o = SubStringWithInstanceVariables.new
|
85
|
+
o.var1 = 'test'
|
86
|
+
original = [o,o,o]
|
87
|
+
|
88
|
+
yaml = Psych.dump original
|
89
|
+
result = Psych.load yaml
|
90
|
+
result.each do |el|
|
91
|
+
assert_same(result[0], el)
|
92
|
+
assert_equal('test', el.var1)
|
93
|
+
end
|
94
|
+
end
|
25
95
|
end
|
26
96
|
end
|
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.3.
|
4
|
+
version: 1.3.4
|
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-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|