psych 2.0.14-java
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.
- checksums.yaml +7 -0
- data/.autotest +18 -0
- data/.gemtest +0 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.rdoc +576 -0
- data/Manifest.txt +114 -0
- data/README.rdoc +71 -0
- data/Rakefile +123 -0
- data/ext/psych/depend +3 -0
- data/ext/psych/extconf.rb +38 -0
- data/ext/psych/psych.c +34 -0
- data/ext/psych/psych.h +20 -0
- data/ext/psych/psych_emitter.c +555 -0
- data/ext/psych/psych_emitter.h +8 -0
- data/ext/psych/psych_parser.c +597 -0
- data/ext/psych/psych_parser.h +6 -0
- data/ext/psych/psych_to_ruby.c +43 -0
- data/ext/psych/psych_to_ruby.h +8 -0
- data/ext/psych/psych_yaml_tree.c +24 -0
- data/ext/psych/psych_yaml_tree.h +8 -0
- data/ext/psych/yaml/LICENSE +19 -0
- data/ext/psych/yaml/api.c +1415 -0
- data/ext/psych/yaml/config.h +10 -0
- data/ext/psych/yaml/dumper.c +394 -0
- data/ext/psych/yaml/emitter.c +2329 -0
- data/ext/psych/yaml/loader.c +459 -0
- data/ext/psych/yaml/parser.c +1370 -0
- data/ext/psych/yaml/reader.c +469 -0
- data/ext/psych/yaml/scanner.c +3576 -0
- data/ext/psych/yaml/writer.c +141 -0
- data/ext/psych/yaml/yaml.h +1971 -0
- data/ext/psych/yaml/yaml_private.h +664 -0
- data/lib/psych.jar +0 -0
- data/lib/psych.rb +504 -0
- data/lib/psych/class_loader.rb +101 -0
- data/lib/psych/coder.rb +94 -0
- data/lib/psych/core_ext.rb +35 -0
- data/lib/psych/deprecated.rb +85 -0
- data/lib/psych/exception.rb +13 -0
- data/lib/psych/handler.rb +249 -0
- data/lib/psych/handlers/document_stream.rb +22 -0
- data/lib/psych/handlers/recorder.rb +39 -0
- data/lib/psych/json/ruby_events.rb +19 -0
- data/lib/psych/json/stream.rb +16 -0
- data/lib/psych/json/tree_builder.rb +12 -0
- data/lib/psych/json/yaml_events.rb +29 -0
- data/lib/psych/nodes.rb +77 -0
- data/lib/psych/nodes/alias.rb +18 -0
- data/lib/psych/nodes/document.rb +60 -0
- data/lib/psych/nodes/mapping.rb +56 -0
- data/lib/psych/nodes/node.rb +55 -0
- data/lib/psych/nodes/scalar.rb +67 -0
- data/lib/psych/nodes/sequence.rb +81 -0
- data/lib/psych/nodes/stream.rb +37 -0
- data/lib/psych/omap.rb +4 -0
- data/lib/psych/parser.rb +51 -0
- data/lib/psych/scalar_scanner.rb +149 -0
- data/lib/psych/set.rb +4 -0
- data/lib/psych/stream.rb +37 -0
- data/lib/psych/streaming.rb +27 -0
- data/lib/psych/syntax_error.rb +21 -0
- data/lib/psych/tree_builder.rb +96 -0
- data/lib/psych/versions.rb +3 -0
- data/lib/psych/visitors.rb +6 -0
- data/lib/psych/visitors/depth_first.rb +26 -0
- data/lib/psych/visitors/emitter.rb +51 -0
- data/lib/psych/visitors/json_tree.rb +24 -0
- data/lib/psych/visitors/to_ruby.rb +404 -0
- data/lib/psych/visitors/visitor.rb +19 -0
- data/lib/psych/visitors/yaml_tree.rb +605 -0
- data/lib/psych/y.rb +9 -0
- data/lib/psych_jars.rb +5 -0
- data/test/psych/handlers/test_recorder.rb +25 -0
- data/test/psych/helper.rb +121 -0
- data/test/psych/json/test_stream.rb +109 -0
- data/test/psych/nodes/test_enumerable.rb +43 -0
- data/test/psych/test_alias_and_anchor.rb +96 -0
- data/test/psych/test_array.rb +57 -0
- data/test/psych/test_boolean.rb +36 -0
- data/test/psych/test_class.rb +36 -0
- data/test/psych/test_coder.rb +206 -0
- data/test/psych/test_date_time.rb +38 -0
- data/test/psych/test_deprecated.rb +214 -0
- data/test/psych/test_document.rb +46 -0
- data/test/psych/test_emitter.rb +93 -0
- data/test/psych/test_encoding.rb +259 -0
- data/test/psych/test_exception.rb +157 -0
- data/test/psych/test_hash.rb +94 -0
- data/test/psych/test_json_tree.rb +65 -0
- data/test/psych/test_merge_keys.rb +180 -0
- data/test/psych/test_nil.rb +18 -0
- data/test/psych/test_null.rb +19 -0
- data/test/psych/test_numeric.rb +45 -0
- data/test/psych/test_object.rb +44 -0
- data/test/psych/test_object_references.rb +71 -0
- data/test/psych/test_omap.rb +75 -0
- data/test/psych/test_parser.rb +339 -0
- data/test/psych/test_psych.rb +168 -0
- data/test/psych/test_safe_load.rb +97 -0
- data/test/psych/test_scalar.rb +11 -0
- data/test/psych/test_scalar_scanner.rb +106 -0
- data/test/psych/test_serialize_subclasses.rb +38 -0
- data/test/psych/test_set.rb +49 -0
- data/test/psych/test_stream.rb +93 -0
- data/test/psych/test_string.rb +226 -0
- data/test/psych/test_struct.rb +49 -0
- data/test/psych/test_symbol.rb +25 -0
- data/test/psych/test_tainted.rb +130 -0
- data/test/psych/test_to_yaml_properties.rb +63 -0
- data/test/psych/test_tree_builder.rb +79 -0
- data/test/psych/test_yaml.rb +1292 -0
- data/test/psych/test_yamldbm.rb +193 -0
- data/test/psych/test_yamlstore.rb +85 -0
- data/test/psych/visitors/test_depth_first.rb +49 -0
- data/test/psych/visitors/test_emitter.rb +144 -0
- data/test/psych/visitors/test_to_ruby.rb +333 -0
- data/test/psych/visitors/test_yaml_tree.rb +173 -0
- metadata +240 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
module Psych
|
2
|
+
module Visitors
|
3
|
+
class DepthFirst < Psych::Visitors::Visitor
|
4
|
+
def initialize block
|
5
|
+
@block = block
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def nary o
|
11
|
+
o.children.each { |x| visit x }
|
12
|
+
@block.call o
|
13
|
+
end
|
14
|
+
alias :visit_Psych_Nodes_Stream :nary
|
15
|
+
alias :visit_Psych_Nodes_Document :nary
|
16
|
+
alias :visit_Psych_Nodes_Sequence :nary
|
17
|
+
alias :visit_Psych_Nodes_Mapping :nary
|
18
|
+
|
19
|
+
def terminal o
|
20
|
+
@block.call o
|
21
|
+
end
|
22
|
+
alias :visit_Psych_Nodes_Scalar :terminal
|
23
|
+
alias :visit_Psych_Nodes_Alias :terminal
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Psych
|
2
|
+
module Visitors
|
3
|
+
class Emitter < Psych::Visitors::Visitor
|
4
|
+
def initialize io, options = {}
|
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
|
16
|
+
end
|
17
|
+
|
18
|
+
def visit_Psych_Nodes_Stream o
|
19
|
+
@handler.start_stream o.encoding
|
20
|
+
o.children.each { |c| accept c }
|
21
|
+
@handler.end_stream
|
22
|
+
end
|
23
|
+
|
24
|
+
def visit_Psych_Nodes_Document o
|
25
|
+
@handler.start_document o.version, o.tag_directives, o.implicit
|
26
|
+
o.children.each { |c| accept c }
|
27
|
+
@handler.end_document o.implicit_end
|
28
|
+
end
|
29
|
+
|
30
|
+
def visit_Psych_Nodes_Scalar o
|
31
|
+
@handler.scalar o.value, o.anchor, o.tag, o.plain, o.quoted, o.style
|
32
|
+
end
|
33
|
+
|
34
|
+
def visit_Psych_Nodes_Sequence o
|
35
|
+
@handler.start_sequence o.anchor, o.tag, o.implicit, o.style
|
36
|
+
o.children.each { |c| accept c }
|
37
|
+
@handler.end_sequence
|
38
|
+
end
|
39
|
+
|
40
|
+
def visit_Psych_Nodes_Mapping o
|
41
|
+
@handler.start_mapping o.anchor, o.tag, o.implicit, o.style
|
42
|
+
o.children.each { |c| accept c }
|
43
|
+
@handler.end_mapping
|
44
|
+
end
|
45
|
+
|
46
|
+
def visit_Psych_Nodes_Alias o
|
47
|
+
@handler.alias o.anchor
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'psych/json/ruby_events'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
module Visitors
|
5
|
+
class JSONTree < YAMLTree
|
6
|
+
include Psych::JSON::RubyEvents
|
7
|
+
|
8
|
+
def self.create options = {}
|
9
|
+
emitter = Psych::JSON::TreeBuilder.new
|
10
|
+
class_loader = ClassLoader.new
|
11
|
+
ss = ScalarScanner.new class_loader
|
12
|
+
new(emitter, ss, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def accept target
|
16
|
+
if target.respond_to?(:encode_with)
|
17
|
+
dump_coder target
|
18
|
+
else
|
19
|
+
send(@dispatch_cache[target.class], target)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,404 @@
|
|
1
|
+
require 'psych/scalar_scanner'
|
2
|
+
require 'psych/class_loader'
|
3
|
+
require 'psych/exception'
|
4
|
+
|
5
|
+
unless defined?(Regexp::NOENCODING)
|
6
|
+
Regexp::NOENCODING = 32
|
7
|
+
end
|
8
|
+
|
9
|
+
module Psych
|
10
|
+
module Visitors
|
11
|
+
###
|
12
|
+
# This class walks a YAML AST, converting each node to Ruby
|
13
|
+
class ToRuby < Psych::Visitors::Visitor
|
14
|
+
def self.create
|
15
|
+
class_loader = ClassLoader.new
|
16
|
+
scanner = ScalarScanner.new class_loader
|
17
|
+
new(scanner, class_loader)
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :class_loader
|
21
|
+
|
22
|
+
def initialize ss, class_loader
|
23
|
+
super()
|
24
|
+
@st = {}
|
25
|
+
@ss = ss
|
26
|
+
@domain_types = Psych.domain_types
|
27
|
+
@class_loader = class_loader
|
28
|
+
end
|
29
|
+
|
30
|
+
def accept target
|
31
|
+
result = super
|
32
|
+
return result if @domain_types.empty? || !target.tag
|
33
|
+
|
34
|
+
key = target.tag.sub(/^[!\/]*/, '').sub(/(,\d+)\//, '\1:')
|
35
|
+
key = "tag:#{key}" unless key =~ /^(?:tag:|x-private)/
|
36
|
+
|
37
|
+
if @domain_types.key? key
|
38
|
+
value, block = @domain_types[key]
|
39
|
+
return block.call value, result
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
def deserialize o
|
46
|
+
if klass = resolve_class(Psych.load_tags[o.tag])
|
47
|
+
instance = klass.allocate
|
48
|
+
|
49
|
+
if instance.respond_to?(:init_with)
|
50
|
+
coder = Psych::Coder.new(o.tag)
|
51
|
+
coder.scalar = o.value
|
52
|
+
instance.init_with coder
|
53
|
+
end
|
54
|
+
|
55
|
+
return instance
|
56
|
+
end
|
57
|
+
|
58
|
+
return o.value if o.quoted
|
59
|
+
return @ss.tokenize(o.value) unless o.tag
|
60
|
+
|
61
|
+
case o.tag
|
62
|
+
when '!binary', 'tag:yaml.org,2002:binary'
|
63
|
+
o.value.unpack('m').first
|
64
|
+
when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str'
|
65
|
+
klass = resolve_class($1)
|
66
|
+
if klass
|
67
|
+
klass.allocate.replace o.value
|
68
|
+
else
|
69
|
+
o.value
|
70
|
+
end
|
71
|
+
when '!ruby/object:BigDecimal'
|
72
|
+
require 'bigdecimal'
|
73
|
+
class_loader.big_decimal._load o.value
|
74
|
+
when "!ruby/object:DateTime"
|
75
|
+
class_loader.date_time
|
76
|
+
require 'date'
|
77
|
+
@ss.parse_time(o.value).to_datetime
|
78
|
+
when '!ruby/encoding'
|
79
|
+
::Encoding.find o.value
|
80
|
+
when "!ruby/object:Complex"
|
81
|
+
class_loader.complex
|
82
|
+
Complex(o.value)
|
83
|
+
when "!ruby/object:Rational"
|
84
|
+
class_loader.rational
|
85
|
+
Rational(o.value)
|
86
|
+
when "!ruby/class", "!ruby/module"
|
87
|
+
resolve_class o.value
|
88
|
+
when "tag:yaml.org,2002:float", "!float"
|
89
|
+
Float(@ss.tokenize(o.value))
|
90
|
+
when "!ruby/regexp"
|
91
|
+
klass = class_loader.regexp
|
92
|
+
o.value =~ /^\/(.*)\/([mixn]*)$/m
|
93
|
+
source = $1
|
94
|
+
options = 0
|
95
|
+
lang = nil
|
96
|
+
($2 || '').split('').each do |option|
|
97
|
+
case option
|
98
|
+
when 'x' then options |= Regexp::EXTENDED
|
99
|
+
when 'i' then options |= Regexp::IGNORECASE
|
100
|
+
when 'm' then options |= Regexp::MULTILINE
|
101
|
+
when 'n' then options |= Regexp::NOENCODING
|
102
|
+
else lang = option
|
103
|
+
end
|
104
|
+
end
|
105
|
+
klass.new(*[source, options, lang].compact)
|
106
|
+
when "!ruby/range"
|
107
|
+
klass = class_loader.range
|
108
|
+
args = o.value.split(/([.]{2,3})/, 2).map { |s|
|
109
|
+
accept Nodes::Scalar.new(s)
|
110
|
+
}
|
111
|
+
args.push(args.delete_at(1) == '...')
|
112
|
+
klass.new(*args)
|
113
|
+
when /^!ruby\/sym(bol)?:?(.*)?$/
|
114
|
+
class_loader.symbolize o.value
|
115
|
+
else
|
116
|
+
@ss.tokenize o.value
|
117
|
+
end
|
118
|
+
end
|
119
|
+
private :deserialize
|
120
|
+
|
121
|
+
def visit_Psych_Nodes_Scalar o
|
122
|
+
register o, deserialize(o)
|
123
|
+
end
|
124
|
+
|
125
|
+
def visit_Psych_Nodes_Sequence o
|
126
|
+
if klass = resolve_class(Psych.load_tags[o.tag])
|
127
|
+
instance = klass.allocate
|
128
|
+
|
129
|
+
if instance.respond_to?(:init_with)
|
130
|
+
coder = Psych::Coder.new(o.tag)
|
131
|
+
coder.seq = o.children.map { |c| accept c }
|
132
|
+
instance.init_with coder
|
133
|
+
end
|
134
|
+
|
135
|
+
return instance
|
136
|
+
end
|
137
|
+
|
138
|
+
case o.tag
|
139
|
+
when nil
|
140
|
+
register_empty(o)
|
141
|
+
when '!omap', 'tag:yaml.org,2002:omap'
|
142
|
+
map = register(o, Psych::Omap.new)
|
143
|
+
o.children.each { |a|
|
144
|
+
map[accept(a.children.first)] = accept a.children.last
|
145
|
+
}
|
146
|
+
map
|
147
|
+
when /^!(?:seq|ruby\/array):(.*)$/
|
148
|
+
klass = resolve_class($1)
|
149
|
+
list = register(o, klass.allocate)
|
150
|
+
o.children.each { |c| list.push accept c }
|
151
|
+
list
|
152
|
+
else
|
153
|
+
register_empty(o)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def visit_Psych_Nodes_Mapping o
|
158
|
+
if Psych.load_tags[o.tag]
|
159
|
+
return revive(resolve_class(Psych.load_tags[o.tag]), o)
|
160
|
+
end
|
161
|
+
return revive_hash(register(o, {}), o) unless o.tag
|
162
|
+
|
163
|
+
case o.tag
|
164
|
+
when /^!ruby\/struct:?(.*)?$/
|
165
|
+
klass = resolve_class($1) if $1
|
166
|
+
|
167
|
+
if klass
|
168
|
+
s = register(o, klass.allocate)
|
169
|
+
|
170
|
+
members = {}
|
171
|
+
struct_members = s.members.map { |x| class_loader.symbolize x }
|
172
|
+
o.children.each_slice(2) do |k,v|
|
173
|
+
member = accept(k)
|
174
|
+
value = accept(v)
|
175
|
+
if struct_members.include?(class_loader.symbolize(member))
|
176
|
+
s.send("#{member}=", value)
|
177
|
+
else
|
178
|
+
members[member.to_s.sub(/^@/, '')] = value
|
179
|
+
end
|
180
|
+
end
|
181
|
+
init_with(s, members, o)
|
182
|
+
else
|
183
|
+
klass = class_loader.struct
|
184
|
+
members = o.children.map { |c| accept c }
|
185
|
+
h = Hash[*members]
|
186
|
+
s = klass.new(*h.map { |k,v|
|
187
|
+
class_loader.symbolize k
|
188
|
+
}).new(*h.map { |k,v| v })
|
189
|
+
register(o, s)
|
190
|
+
s
|
191
|
+
end
|
192
|
+
|
193
|
+
when /^!ruby\/object:?(.*)?$/
|
194
|
+
name = $1 || 'Object'
|
195
|
+
|
196
|
+
if name == 'Complex'
|
197
|
+
class_loader.complex
|
198
|
+
h = Hash[*o.children.map { |c| accept c }]
|
199
|
+
register o, Complex(h['real'], h['image'])
|
200
|
+
elsif name == 'Rational'
|
201
|
+
class_loader.rational
|
202
|
+
h = Hash[*o.children.map { |c| accept c }]
|
203
|
+
register o, Rational(h['numerator'], h['denominator'])
|
204
|
+
elsif name == 'Hash'
|
205
|
+
revive_hash(register(o, {}), o)
|
206
|
+
else
|
207
|
+
obj = revive((resolve_class(name) || class_loader.object), o)
|
208
|
+
obj
|
209
|
+
end
|
210
|
+
|
211
|
+
when /^!(?:str|ruby\/string)(?::(.*))?$/, 'tag:yaml.org,2002:str'
|
212
|
+
klass = resolve_class($1)
|
213
|
+
members = {}
|
214
|
+
string = nil
|
215
|
+
|
216
|
+
o.children.each_slice(2) do |k,v|
|
217
|
+
key = accept k
|
218
|
+
value = accept v
|
219
|
+
|
220
|
+
if key == 'str'
|
221
|
+
if klass
|
222
|
+
string = klass.allocate.replace value
|
223
|
+
else
|
224
|
+
string = value
|
225
|
+
end
|
226
|
+
register(o, string)
|
227
|
+
else
|
228
|
+
members[key] = value
|
229
|
+
end
|
230
|
+
end
|
231
|
+
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)
|
232
|
+
when /^!ruby\/array:(.*)$/
|
233
|
+
klass = resolve_class($1)
|
234
|
+
list = register(o, klass.allocate)
|
235
|
+
|
236
|
+
members = Hash[o.children.map { |c| accept c }.each_slice(2).to_a]
|
237
|
+
list.replace members['internal']
|
238
|
+
|
239
|
+
members['ivars'].each do |ivar, v|
|
240
|
+
list.instance_variable_set ivar, v
|
241
|
+
end
|
242
|
+
list
|
243
|
+
|
244
|
+
when '!ruby/range'
|
245
|
+
klass = class_loader.range
|
246
|
+
h = Hash[*o.children.map { |c| accept c }]
|
247
|
+
register o, klass.new(h['begin'], h['end'], h['excl'])
|
248
|
+
|
249
|
+
when /^!ruby\/exception:?(.*)?$/
|
250
|
+
h = Hash[*o.children.map { |c| accept c }]
|
251
|
+
|
252
|
+
e = build_exception((resolve_class($1) || class_loader.exception),
|
253
|
+
h.delete('message'))
|
254
|
+
init_with(e, h, o)
|
255
|
+
|
256
|
+
when '!set', 'tag:yaml.org,2002:set'
|
257
|
+
set = class_loader.psych_set.new
|
258
|
+
@st[o.anchor] = set if o.anchor
|
259
|
+
o.children.each_slice(2) do |k,v|
|
260
|
+
set[accept(k)] = accept(v)
|
261
|
+
end
|
262
|
+
set
|
263
|
+
|
264
|
+
when /^!ruby\/hash-with-ivars(?::(.*))?$/
|
265
|
+
hash = $1 ? resolve_class($1).allocate : {}
|
266
|
+
register o, hash
|
267
|
+
o.children.each_slice(2) do |key, value|
|
268
|
+
case key.value
|
269
|
+
when 'elements'
|
270
|
+
revive_hash hash, value
|
271
|
+
when 'ivars'
|
272
|
+
value.children.each_slice(2) do |k,v|
|
273
|
+
hash.instance_variable_set accept(k), accept(v)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
hash
|
278
|
+
|
279
|
+
when /^!map:(.*)$/, /^!ruby\/hash:(.*)$/
|
280
|
+
revive_hash register(o, resolve_class($1).allocate), o
|
281
|
+
|
282
|
+
when '!omap', 'tag:yaml.org,2002:omap'
|
283
|
+
map = register(o, class_loader.psych_omap.new)
|
284
|
+
o.children.each_slice(2) do |l,r|
|
285
|
+
map[accept(l)] = accept r
|
286
|
+
end
|
287
|
+
map
|
288
|
+
|
289
|
+
when /^!ruby\/marshalable:(.*)$/
|
290
|
+
name = $1
|
291
|
+
klass = resolve_class(name)
|
292
|
+
obj = register(o, klass.allocate)
|
293
|
+
|
294
|
+
if obj.respond_to?(:init_with)
|
295
|
+
init_with(obj, revive_hash({}, o), o)
|
296
|
+
elsif obj.respond_to?(:marshal_load)
|
297
|
+
marshal_data = o.children.map(&method(:accept))
|
298
|
+
obj.marshal_load(marshal_data)
|
299
|
+
obj
|
300
|
+
else
|
301
|
+
raise ArgumentError, "Cannot deserialize #{name}"
|
302
|
+
end
|
303
|
+
|
304
|
+
else
|
305
|
+
revive_hash(register(o, {}), o)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def visit_Psych_Nodes_Document o
|
310
|
+
accept o.root
|
311
|
+
end
|
312
|
+
|
313
|
+
def visit_Psych_Nodes_Stream o
|
314
|
+
o.children.map { |c| accept c }
|
315
|
+
end
|
316
|
+
|
317
|
+
def visit_Psych_Nodes_Alias o
|
318
|
+
@st.fetch(o.anchor) { raise BadAlias, "Unknown alias: #{o.anchor}" }
|
319
|
+
end
|
320
|
+
|
321
|
+
private
|
322
|
+
def register node, object
|
323
|
+
@st[node.anchor] = object if node.anchor
|
324
|
+
object
|
325
|
+
end
|
326
|
+
|
327
|
+
def register_empty object
|
328
|
+
list = register(object, [])
|
329
|
+
object.children.each { |c| list.push accept c }
|
330
|
+
list
|
331
|
+
end
|
332
|
+
|
333
|
+
def revive_hash hash, o
|
334
|
+
o.children.each_slice(2) { |k,v|
|
335
|
+
key = accept(k)
|
336
|
+
val = accept(v)
|
337
|
+
|
338
|
+
if key == '<<' && k.tag != "tag:yaml.org,2002:str"
|
339
|
+
case v
|
340
|
+
when Nodes::Alias, Nodes::Mapping
|
341
|
+
begin
|
342
|
+
hash.merge! val
|
343
|
+
rescue TypeError
|
344
|
+
hash[key] = val
|
345
|
+
end
|
346
|
+
when Nodes::Sequence
|
347
|
+
begin
|
348
|
+
h = {}
|
349
|
+
val.reverse_each do |value|
|
350
|
+
h.merge! value
|
351
|
+
end
|
352
|
+
hash.merge! h
|
353
|
+
rescue TypeError
|
354
|
+
hash[key] = val
|
355
|
+
end
|
356
|
+
else
|
357
|
+
hash[key] = val
|
358
|
+
end
|
359
|
+
else
|
360
|
+
hash[key] = val
|
361
|
+
end
|
362
|
+
|
363
|
+
}
|
364
|
+
hash
|
365
|
+
end
|
366
|
+
|
367
|
+
def merge_key hash, key, val
|
368
|
+
end
|
369
|
+
|
370
|
+
def revive klass, node
|
371
|
+
s = register(node, klass.allocate)
|
372
|
+
init_with(s, revive_hash({}, node), node)
|
373
|
+
end
|
374
|
+
|
375
|
+
def init_with o, h, node
|
376
|
+
c = Psych::Coder.new(node.tag)
|
377
|
+
c.map = h
|
378
|
+
|
379
|
+
if o.respond_to?(:init_with)
|
380
|
+
o.init_with c
|
381
|
+
elsif o.respond_to?(:yaml_initialize)
|
382
|
+
if $VERBOSE
|
383
|
+
warn "Implementing #{o.class}#yaml_initialize is deprecated, please implement \"init_with(coder)\""
|
384
|
+
end
|
385
|
+
o.yaml_initialize c.tag, c.map
|
386
|
+
else
|
387
|
+
h.each { |k,v| o.instance_variable_set(:"@#{k}", v) }
|
388
|
+
end
|
389
|
+
o
|
390
|
+
end
|
391
|
+
|
392
|
+
# Convert +klassname+ to a Class
|
393
|
+
def resolve_class klassname
|
394
|
+
class_loader.load klassname
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
class NoAliasRuby < ToRuby
|
399
|
+
def visit_Psych_Nodes_Alias o
|
400
|
+
raise BadAlias, "Unknown alias: #{o.anchor}"
|
401
|
+
end
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|