RbYAML 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rbyaml.rb +14 -256
- data/lib/rbyaml.rb.~1.2.~ +383 -0
- data/lib/rbyaml/composer.rb +9 -11
- data/lib/rbyaml/{composer.rb.~1.2.~ → composer.rb.~1.3.~} +28 -25
- data/lib/rbyaml/constants.rb +95 -0
- data/lib/rbyaml/constructor.rb +180 -89
- data/lib/rbyaml/{constructor.rb.~1.2.~ → constructor.rb.~1.9.~} +137 -95
- data/lib/rbyaml/dumper.rb +12 -9
- data/lib/rbyaml/dumper.rb.~1.3.~ +36 -0
- data/lib/rbyaml/emitter.rb +14 -28
- data/lib/rbyaml/{emitter.rb.~1.2.~ → emitter.rb.~1.6.~} +22 -33
- data/lib/rbyaml/error.rb +4 -57
- data/lib/rbyaml/error.rb.~1.2.~ +75 -0
- data/lib/rbyaml/events.rb +8 -14
- data/lib/rbyaml/{events.rb.~1.2.~ → events.rb.~1.4.~} +29 -6
- data/lib/rbyaml/nodes.rb +5 -5
- data/lib/rbyaml/{nodes.rb.~1.2.~ → nodes.rb.~1.3.~} +13 -9
- data/lib/rbyaml/parser.rb +70 -108
- data/lib/rbyaml/parser.rb.~1.4.~ +632 -0
- data/lib/rbyaml/representer.rb +19 -157
- data/lib/rbyaml/representer.rb.old +317 -0
- data/lib/rbyaml/{representer.rb.~1.2.~ → representer.rb.~1.5.~} +60 -26
- data/lib/rbyaml/resolver.rb +6 -6
- data/lib/rbyaml/{resolver.rb.~1.1.~ → resolver.rb.~1.6.~} +20 -20
- data/lib/rbyaml/rubytypes.rb +391 -0
- data/lib/rbyaml/scanner.rb +123 -225
- data/lib/rbyaml/{scanner.rb.~1.2.~ → scanner.rb.~1.5.~} +466 -378
- data/lib/rbyaml/serializer.rb +9 -9
- data/lib/rbyaml/{serializer.rb.~1.2.~ → serializer.rb.~1.4.~} +19 -17
- data/lib/rbyaml/stream.rb +48 -0
- data/lib/rbyaml/tag.rb +72 -0
- data/lib/rbyaml/tokens.rb +22 -16
- data/lib/rbyaml/{tokens.rb.~1.2.~ → tokens.rb.~1.3.~} +44 -4
- data/lib/rbyaml/types.rb +146 -0
- data/lib/rbyaml/util.rb.~1.3.~ +38 -0
- data/lib/rbyaml/yaml.rb +22 -32
- data/lib/rbyaml/{yaml.rb.~1.2.~ → yaml.rb.~1.5.~} +17 -17
- data/test/load_one.rb +6 -0
- data/test/load_one_yaml.rb +6 -0
- data/test/output_events.rb +9 -0
- data/test/test_add_ctor.rb +51 -0
- data/test/test_add_ctor.rb.~1.1.~ +30 -0
- data/test/test_bm.rb +2 -2
- data/test/test_bm.rb.~1.1.~ +28 -0
- data/test/test_gems.rb +10 -0
- data/test/test_one.rb.~1.1.~ +5 -0
- data/test/test_one_syck.rb +5 -0
- data/test/test_rbyaml.rb +63 -32
- data/test/test_rbyaml.rb.~1.6.~ +59 -0
- data/test/{test_rbyaml.rb.~1.2.~ → test_rbyaml_old.rb} +13 -4
- data/test/test_time_events.rb +24 -0
- data/test/test_time_nodes.rb +24 -0
- data/test/test_time_tokens.rb +24 -0
- data/test/yaml/gems_new.yml +147456 -0
- data/test/yaml/test1.rb +8 -0
- data/test/yaml/test10.rb +14 -0
- data/test/yaml/test11.rb +13 -0
- data/test/yaml/test12.rb +9 -0
- data/test/yaml/test13.rb +9 -0
- data/test/yaml/test14.rb +13 -0
- data/test/yaml/test15.rb +12 -0
- data/test/yaml/test16.rb +11 -0
- data/test/yaml/test16.rb.~1.1.~ +11 -0
- data/test/yaml/test17.rb +10 -0
- data/test/yaml/test18.rb +13 -0
- data/test/yaml/test19.rb +9 -0
- data/test/yaml/test19.yml +1 -1
- data/test/yaml/test2.rb +8 -0
- data/test/yaml/test20.rb +11 -0
- data/test/yaml/test20.rb.~1.1.~ +9 -0
- data/test/yaml/test20.yml +1 -1
- data/test/yaml/test3.rb +13 -0
- data/test/yaml/test4.rb +13 -0
- data/test/yaml/test5.rb +8 -0
- data/test/yaml/test6.rb +10 -0
- data/test/yaml/test7.rb +15 -0
- data/test/yaml/test8.rb +15 -0
- data/test/yaml/test9.rb +13 -0
- metadata +61 -16
- data/lib/rbyaml/dumper.rb.~1.2.~ +0 -43
- data/lib/rbyaml/parser.rb.~1.2.~ +0 -494
@@ -1,39 +1,60 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'set'
|
3
3
|
|
4
|
+
require 'rbyaml/util'
|
5
|
+
|
4
6
|
require 'rbyaml/error'
|
5
7
|
require 'rbyaml/nodes'
|
6
8
|
require 'rbyaml/composer'
|
7
9
|
|
10
|
+
class Symbol
|
11
|
+
def __call(obj,*args)
|
12
|
+
obj.send(self,*args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Proc
|
17
|
+
def __call(obj,*args)
|
18
|
+
call(obj,*args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Method
|
23
|
+
def __call(obj,*args)
|
24
|
+
call(*args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
8
29
|
module RbYAML
|
9
30
|
class ConstructorError < MarkedYAMLError
|
10
31
|
end
|
11
32
|
|
12
|
-
|
13
|
-
include Composer
|
14
|
-
|
33
|
+
class BaseConstructor
|
15
34
|
@@yaml_constructors = {}
|
16
35
|
@@yaml_multi_constructors = {}
|
36
|
+
@@yaml_multi_regexps = {}
|
17
37
|
|
18
|
-
def
|
38
|
+
def initialize(composer)
|
39
|
+
@composer = composer
|
19
40
|
@constructed_objects = {}
|
20
41
|
@recursive_objects = {}
|
21
42
|
end
|
22
43
|
|
23
44
|
def check_data
|
24
45
|
# If there are more documents available?
|
25
|
-
check_node
|
46
|
+
@composer.check_node
|
26
47
|
end
|
27
48
|
|
28
49
|
def get_data
|
29
50
|
# Construct and return the next document.
|
30
|
-
construct_document(get_node) if check_node
|
51
|
+
construct_document(@composer.get_node) if @composer.check_node
|
31
52
|
end
|
32
53
|
|
33
54
|
def each_document
|
34
55
|
# Iterator protocol.
|
35
|
-
while check_node
|
36
|
-
yield construct_document(get_node)
|
56
|
+
while @composer.check_node
|
57
|
+
yield construct_document(@composer.get_node)
|
37
58
|
end
|
38
59
|
end
|
39
60
|
|
@@ -43,57 +64,65 @@ module RbYAML
|
|
43
64
|
@recursive_objects = {}
|
44
65
|
data
|
45
66
|
end
|
67
|
+
|
68
|
+
class RecursiveProxy
|
69
|
+
attr_writer :value
|
70
|
+
def method_missing(*args)
|
71
|
+
@value.send(*args)
|
72
|
+
end
|
73
|
+
def class
|
74
|
+
@value.class
|
75
|
+
end
|
76
|
+
def to_s
|
77
|
+
@value.to_s
|
78
|
+
end
|
79
|
+
end
|
46
80
|
|
47
81
|
def construct_object(node)
|
48
82
|
return @constructed_objects[node] if @constructed_objects.include?(node)
|
49
|
-
|
50
|
-
|
51
|
-
constructor
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
constructor = lambda { |node| send(:construct_ruby_object,RbYAML::tagged_classes[node.tag],node) }
|
57
|
-
else
|
58
|
-
through = false
|
59
|
-
for tag_prefix in @@yaml_multi_constructors.keys
|
83
|
+
@constructed_objects[node] = RecursiveProxy.new
|
84
|
+
constructor = @@yaml_constructors[node.tag]
|
85
|
+
if !constructor
|
86
|
+
ruby_cls = RbYAML::tagged_classes[node.tag]
|
87
|
+
if ruby_cls && (ruby_cls.method_defined?(:yaml_initialize) || ruby_cls.respond_to?(:yaml_new))
|
88
|
+
constructor = lambda { |obj,node| send(:construct_ruby_object,ruby_cls,node) }
|
89
|
+
else
|
60
90
|
through = true
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
constructor = lambda { |node|
|
65
|
-
|
66
|
-
|
91
|
+
for tag_prefix,reg in @@yaml_multi_regexps
|
92
|
+
if reg =~ node.tag
|
93
|
+
tag_suffix = node.tag[tag_prefix.length..-1]
|
94
|
+
constructor = lambda { |obj, node| @@yaml_multi_constructors[tag_prefix].__call(self,tag_suffix, node) }
|
95
|
+
through = false
|
96
|
+
break
|
67
97
|
end
|
68
|
-
break
|
69
98
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
constructor = lambda { |node| send(@@yaml_multi_constructors[nil],node.tag, node) }
|
99
|
+
if through
|
100
|
+
ctor = @@yaml_multi_constructors[nil]
|
101
|
+
if ctor
|
102
|
+
constructor = lambda { |obj, node| ctor.__call(self,node.tag,node) }
|
75
103
|
else
|
76
|
-
|
104
|
+
ctor = @@yaml_constructors[nil]
|
105
|
+
if ctor
|
106
|
+
constructor = lambda { |obj, node| ctor.__call(self,node)}
|
107
|
+
else
|
108
|
+
constructor = lambda { |obj, node| construct_primitive(node) }
|
109
|
+
end
|
77
110
|
end
|
78
|
-
elsif @@yaml_constructors.include?(nil)
|
79
|
-
constructor = @@yaml_constructors[nil]
|
80
|
-
else
|
81
|
-
constructor = lambda { |node| construct_primitive(node) }
|
82
111
|
end
|
83
112
|
end
|
84
113
|
end
|
85
|
-
data =
|
114
|
+
data = constructor.__call(self,node)
|
115
|
+
@constructed_objects[node].value = data
|
86
116
|
@constructed_objects[node] = data
|
87
|
-
@recursive_objects.delete(node)
|
88
117
|
data
|
89
118
|
end
|
90
119
|
|
91
120
|
def construct_primitive(node)
|
92
|
-
if
|
121
|
+
if node.__is_scalar
|
93
122
|
construct_scalar(node)
|
94
|
-
elsif
|
123
|
+
elsif node.__is_sequence
|
95
124
|
construct_sequence(node)
|
96
|
-
elsif
|
125
|
+
elsif node.__is_mapping
|
97
126
|
construct_mapping(node)
|
98
127
|
else
|
99
128
|
puts node.tag
|
@@ -101,8 +130,8 @@ module RbYAML
|
|
101
130
|
end
|
102
131
|
|
103
132
|
def construct_scalar(node)
|
104
|
-
if !
|
105
|
-
if
|
133
|
+
if !node.__is_scalar
|
134
|
+
if node.__is_mapping
|
106
135
|
for key_node in node.value.keys
|
107
136
|
if key_node.tag == "tag:yaml.org,2002:value"
|
108
137
|
return construct_scalar(node.value[key_node])
|
@@ -114,52 +143,50 @@ module RbYAML
|
|
114
143
|
node.value
|
115
144
|
end
|
116
145
|
|
146
|
+
def construct_private_type(node)
|
147
|
+
# construct_scalar(node)
|
148
|
+
PrivateType.new(node.tag,node.value)
|
149
|
+
end
|
150
|
+
|
117
151
|
def construct_sequence(node)
|
118
|
-
raise ConstructorError.new(nil,nil,"expected a sequence node, but found #{node.tid}",node.start_mark) if !
|
119
|
-
|
120
|
-
for child in node.value
|
121
|
-
sequence << construct_object(child)
|
122
|
-
end
|
123
|
-
sequence
|
152
|
+
raise ConstructorError.new(nil,nil,"expected a sequence node, but found #{node.tid}",node.start_mark) if !node.__is_sequence
|
153
|
+
node.value.map {|child| construct_object(child) }
|
124
154
|
end
|
125
155
|
|
126
156
|
def construct_mapping(node)
|
127
|
-
raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !
|
157
|
+
raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !node.__is_mapping
|
128
158
|
mapping = {}
|
129
159
|
merge = nil
|
130
|
-
for key_node in node.value
|
160
|
+
for key_node,value_node in node.value
|
131
161
|
if key_node.tag == "tag:yaml.org,2002:merge"
|
132
162
|
raise ConstructorError.new("while constructing a mapping", node.start_mark,"found duplicate merge key", key_node.start_mark) if !merge.nil?
|
133
|
-
value_node
|
134
|
-
if MappingNode === value_node
|
163
|
+
if value_node.__is_mapping
|
135
164
|
merge = [construct_mapping(value_node)]
|
136
|
-
elsif
|
165
|
+
elsif value_node.__is_sequence
|
137
166
|
merge = []
|
138
167
|
for subnode in value_node.value
|
139
|
-
if !
|
168
|
+
if !subnode.__is_mapping
|
140
169
|
raise ConstructorError.new("while constructing a mapping",node.start_mark,"expected a mapping for merging, but found #{subnode.tid}", subnode.start_mark)
|
141
170
|
end
|
142
|
-
merge
|
171
|
+
merge.unshift(construct_mapping(subnode))
|
143
172
|
end
|
144
|
-
merge.reverse!
|
145
173
|
else
|
146
174
|
raise ConstructorError.new("while constructing a mapping", node.start_mark,"expected a mapping or list of mappings for merging, but found #{value_node.tid}", value_node.start_mark)
|
147
175
|
end
|
148
176
|
elsif key_node.tag == "tag:yaml.org,2002:value"
|
149
177
|
raise ConstructorError.new("while construction a mapping", node.start_mark,"found duplicate value key", key_node.start_mark) if mapping.include?("=")
|
150
|
-
value = construct_object(
|
178
|
+
value = construct_object(value_node)
|
151
179
|
mapping["="] = value
|
152
|
-
|
153
180
|
else
|
154
181
|
key = construct_object(key_node)
|
182
|
+
value = construct_object(value_node)
|
183
|
+
mapping[key] = value
|
155
184
|
# raise ConstructorError.new("while constructing a mapping", node.start_mark,"found duplicate key", key_node.start_mark) if mapping.include?(key)
|
156
185
|
end
|
157
|
-
value = construct_object(node.value[key_node])
|
158
|
-
mapping[key] = value
|
159
186
|
end
|
160
187
|
if !merge.nil?
|
161
188
|
merge << mapping
|
162
|
-
mapping = {}
|
189
|
+
mapping = { }
|
163
190
|
for submapping in merge
|
164
191
|
mapping.merge!(submapping)
|
165
192
|
end
|
@@ -168,14 +195,8 @@ module RbYAML
|
|
168
195
|
end
|
169
196
|
|
170
197
|
def construct_pairs(node)
|
171
|
-
raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !
|
172
|
-
|
173
|
-
for key_node in node.value.keys
|
174
|
-
key = construct_object(key_node)
|
175
|
-
value = construct_object(node.value[key_node])
|
176
|
-
pairs << [key, value]
|
177
|
-
end
|
178
|
-
pairs
|
198
|
+
raise ConstructorError.new(nil,nil,"expected a mapping node, but found #{node.tid}",node.start_mark) if !node.__is_mapping
|
199
|
+
node.value.collect {|key_node,value_node| [construct_object(key_node), construct_object(value_node)] }
|
179
200
|
end
|
180
201
|
|
181
202
|
def self.add_constructor(tag, constructor)
|
@@ -184,20 +205,19 @@ module RbYAML
|
|
184
205
|
|
185
206
|
def self.add_multi_constructor(tag_prefix, multi_constructor)
|
186
207
|
@@yaml_multi_constructors[tag_prefix] = multi_constructor
|
208
|
+
@@yaml_multi_regexps[tag_prefix] = Regexp.new("^"+Regexp.escape(tag_prefix))
|
187
209
|
end
|
188
210
|
end
|
189
211
|
|
190
|
-
|
191
|
-
include BaseConstructor
|
192
|
-
|
212
|
+
class SafeConstructor < BaseConstructor
|
193
213
|
def construct_yaml_null(node)
|
194
214
|
construct_scalar(node)
|
195
215
|
nil
|
196
216
|
end
|
197
217
|
|
198
218
|
BOOL_VALUES = {
|
199
|
-
"y" => true,
|
200
|
-
"n" => false,
|
219
|
+
# "y" => true,
|
220
|
+
# "n" => false,
|
201
221
|
"yes" => true,
|
202
222
|
"no" => false,
|
203
223
|
"true" => true,
|
@@ -208,23 +228,32 @@ module RbYAML
|
|
208
228
|
|
209
229
|
def construct_yaml_bool(node)
|
210
230
|
value = construct_scalar(node)
|
211
|
-
|
231
|
+
BOOL_VALUES[value.downcase]
|
212
232
|
end
|
213
233
|
|
214
234
|
def construct_yaml_int(node)
|
215
235
|
value = construct_scalar(node).to_s
|
216
236
|
value = value.gsub(/_/, '')
|
217
237
|
sign = +1
|
218
|
-
|
219
|
-
|
238
|
+
first = value[0]
|
239
|
+
if first == ?-
|
240
|
+
sign = -1
|
241
|
+
value.slice!(0)
|
242
|
+
elsif first == ?+
|
243
|
+
value.slice!(0)
|
244
|
+
end
|
245
|
+
base = 10
|
220
246
|
if value == "0"
|
221
247
|
return 0
|
222
248
|
elsif value[0..1] == "0b"
|
223
|
-
|
249
|
+
value.slice!(0..1)
|
250
|
+
base = 2
|
224
251
|
elsif value[0..1] == "0x"
|
225
|
-
|
252
|
+
value.slice!(0..1)
|
253
|
+
base = 16
|
226
254
|
elsif value[0] == ?0
|
227
|
-
|
255
|
+
value.slice!(0)
|
256
|
+
base = 8
|
228
257
|
elsif value.include?(?:)
|
229
258
|
digits = (value.split(/:/).map {|val| val.to_i}).reverse
|
230
259
|
base = 1
|
@@ -237,6 +266,7 @@ module RbYAML
|
|
237
266
|
else
|
238
267
|
return sign*value.to_i
|
239
268
|
end
|
269
|
+
return sign*value.to_i(base)
|
240
270
|
end
|
241
271
|
|
242
272
|
INF_VALUE = +1.0/0.0
|
@@ -246,12 +276,17 @@ module RbYAML
|
|
246
276
|
value = construct_scalar(node).to_s
|
247
277
|
value = value.gsub(/_/, '')
|
248
278
|
sign = +1
|
249
|
-
|
250
|
-
|
279
|
+
first = value[0]
|
280
|
+
if first == ?-
|
281
|
+
sign = -1
|
282
|
+
value.slice!(0)
|
283
|
+
elsif first == ?+
|
284
|
+
value.slice!(0)
|
285
|
+
end
|
251
286
|
if value.downcase == ".inf"
|
252
|
-
return sign*
|
287
|
+
return sign*INF_VALUE
|
253
288
|
elsif value.downcase == ".nan"
|
254
|
-
return
|
289
|
+
return NAN_VALUE
|
255
290
|
elsif value.include?(?:)
|
256
291
|
digits = (value.split(/:/).map {|val| val.to_f}).reverse
|
257
292
|
base = 1
|
@@ -268,14 +303,21 @@ module RbYAML
|
|
268
303
|
|
269
304
|
def construct_yaml_binary(node)
|
270
305
|
value = construct_scalar(node)
|
271
|
-
Base64.decode64(value.to_s)
|
306
|
+
Base64.decode64(value.split(/[\n\x85]|(?:\r[^\n])/).to_s)
|
272
307
|
end
|
273
308
|
|
274
309
|
TIMESTAMP_REGEXP = /^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:(?:[Tt]|[ \t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\.([0-9]*))?(?:[ \t]*(?:Z|([-+][0-9][0-9]?)(?::([0-9][0-9])?)?))?)?$/
|
310
|
+
|
311
|
+
YMD_REGEXP = /^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)$/
|
275
312
|
|
276
313
|
def construct_yaml_timestamp(node)
|
277
|
-
|
278
|
-
|
314
|
+
if (match = YMD_REGEXP.match(node.value))
|
315
|
+
values = match.captures.map {|val| val.to_i}
|
316
|
+
return Date.new(values[0],values[1],values[2])
|
317
|
+
end
|
318
|
+
unless (match = TIMESTAMP_REGEXP.match(node.value))
|
319
|
+
return construct_private_type(node)
|
320
|
+
end
|
279
321
|
values = match.captures.map {|val| val.to_i}
|
280
322
|
fraction = values[6]
|
281
323
|
if fraction != 0
|
@@ -292,11 +334,11 @@ module RbYAML
|
|
292
334
|
# Note: we do not check for duplicate keys, because its too
|
293
335
|
# CPU-expensive.
|
294
336
|
raise ConstructorError.new("while constructing an ordered map", node.start_mark,
|
295
|
-
"expected a sequence, but found #{node.tid}", node.start_mark) if !
|
337
|
+
"expected a sequence, but found #{node.tid}", node.start_mark) if !node.__is_sequence
|
296
338
|
omap = []
|
297
339
|
for subnode in node.value
|
298
340
|
raise ConstructorError.new("while constructing an ordered map", node.start_mark,
|
299
|
-
"expected a mapping of length 1, but found #{subnode.tid}",subnode.start_mark) if !
|
341
|
+
"expected a mapping of length 1, but found #{subnode.tid}",subnode.start_mark) if !subnode.__is_mapping
|
300
342
|
raise ConstructorError.new("while constructing an ordered map", node.start_mark,
|
301
343
|
"expected a single mapping item, but found #{subnode.value.length} items",subnode.start_mark) if subnode.value.length != 1
|
302
344
|
key_node = subnode.value.keys[0]
|
@@ -316,7 +358,8 @@ module RbYAML
|
|
316
358
|
end
|
317
359
|
|
318
360
|
def construct_yaml_str(node)
|
319
|
-
construct_scalar(node).to_s
|
361
|
+
val = construct_scalar(node).to_s
|
362
|
+
val.empty? ? nil : val
|
320
363
|
end
|
321
364
|
|
322
365
|
def construct_yaml_seq(node)
|
@@ -359,7 +402,7 @@ module RbYAML
|
|
359
402
|
end
|
360
403
|
end
|
361
404
|
|
362
|
-
|
405
|
+
SafeConstructor::add_constructor('tag:yaml.org,2002:null',:construct_yaml_null)
|
363
406
|
BaseConstructor::add_constructor('tag:yaml.org,2002:bool',:construct_yaml_bool)
|
364
407
|
BaseConstructor::add_constructor('tag:yaml.org,2002:int',:construct_yaml_int)
|
365
408
|
BaseConstructor::add_constructor('tag:yaml.org,2002:float',:construct_yaml_float)
|
@@ -371,11 +414,10 @@ module RbYAML
|
|
371
414
|
BaseConstructor::add_constructor('tag:yaml.org,2002:str',:construct_yaml_str)
|
372
415
|
BaseConstructor::add_constructor('tag:yaml.org,2002:seq',:construct_yaml_seq)
|
373
416
|
BaseConstructor::add_constructor('tag:yaml.org,2002:map',:construct_yaml_map)
|
374
|
-
BaseConstructor::add_constructor(nil,:
|
417
|
+
BaseConstructor::add_constructor(nil,:construct_private_type)
|
375
418
|
|
376
419
|
BaseConstructor::add_multi_constructor("!ruby/object:",:construct_ruby)
|
377
420
|
|
378
|
-
|
379
|
-
include SafeConstructor
|
421
|
+
class Constructor < SafeConstructor
|
380
422
|
end
|
381
423
|
end
|
data/lib/rbyaml/dumper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rbyaml/constants'
|
1
2
|
require 'rbyaml/emitter'
|
2
3
|
require 'rbyaml/serializer'
|
3
4
|
require 'rbyaml/representer'
|
@@ -6,30 +7,32 @@ require 'rbyaml/resolver'
|
|
6
7
|
module RbYAML
|
7
8
|
class CommonDumper
|
8
9
|
attr_accessor :emitter, :serializer, :representer, :resolver
|
9
|
-
def initialize(stream,
|
10
|
+
def initialize(stream,opts={})
|
10
11
|
super()
|
11
|
-
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
12
|
+
opts = DEFAULTS.merge(opts)
|
13
|
+
@emitter = opts[:Emitter].new(stream,opts)
|
14
|
+
@resolver = opts[:Resolver].new
|
15
|
+
@serializer = opts[:Serializer].new(@emitter,@resolver,opts)
|
16
|
+
@representer = opts[:Representer].new(@serializer,opts)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
20
|
class BaseDumper < CommonDumper
|
19
21
|
attr_accessor
|
20
|
-
def initialize(stream,
|
21
|
-
super
|
22
|
+
def initialize(stream,opts={})
|
23
|
+
super(stream,DEFAULTS.merge({:Representer=>RbYAML::BaseRepresenter, :Resolver=>RbYAML::BaseResolver}).merge(opts))
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
class SafeDumper < CommonDumper
|
26
|
-
def initialize(stream,
|
28
|
+
def initialize(stream,opts={})
|
29
|
+
super(stream,DEFAULTS.merge({:Representer=>RbYAML::SafeRepresenter}).merge(opts))
|
27
30
|
super
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
class Dumper < CommonDumper
|
32
|
-
def initialize(stream,
|
35
|
+
def initialize(stream,opts={})
|
33
36
|
super
|
34
37
|
end
|
35
38
|
end
|