psych-shopifork 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +15 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.rdoc +414 -0
  6. data/Manifest.txt +113 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +72 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +36 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +538 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +579 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1392 -0
  23. data/ext/psych/yaml/config.h +11 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2335 -0
  26. data/ext/psych/yaml/loader.c +432 -0
  27. data/ext/psych/yaml/parser.c +1374 -0
  28. data/ext/psych/yaml/reader.c +465 -0
  29. data/ext/psych/yaml/scanner.c +3570 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +643 -0
  33. data/lib/psych.rb +497 -0
  34. data/lib/psych/class_loader.rb +101 -0
  35. data/lib/psych/coder.rb +94 -0
  36. data/lib/psych/core_ext.rb +35 -0
  37. data/lib/psych/deprecated.rb +85 -0
  38. data/lib/psych/exception.rb +13 -0
  39. data/lib/psych/handler.rb +249 -0
  40. data/lib/psych/handlers/document_stream.rb +22 -0
  41. data/lib/psych/handlers/recorder.rb +39 -0
  42. data/lib/psych/json/ruby_events.rb +19 -0
  43. data/lib/psych/json/stream.rb +16 -0
  44. data/lib/psych/json/tree_builder.rb +12 -0
  45. data/lib/psych/json/yaml_events.rb +29 -0
  46. data/lib/psych/nodes.rb +77 -0
  47. data/lib/psych/nodes/alias.rb +18 -0
  48. data/lib/psych/nodes/document.rb +60 -0
  49. data/lib/psych/nodes/mapping.rb +56 -0
  50. data/lib/psych/nodes/node.rb +55 -0
  51. data/lib/psych/nodes/scalar.rb +67 -0
  52. data/lib/psych/nodes/sequence.rb +81 -0
  53. data/lib/psych/nodes/stream.rb +37 -0
  54. data/lib/psych/omap.rb +4 -0
  55. data/lib/psych/parser.rb +51 -0
  56. data/lib/psych/scalar_scanner.rb +149 -0
  57. data/lib/psych/set.rb +4 -0
  58. data/lib/psych/stream.rb +37 -0
  59. data/lib/psych/streaming.rb +27 -0
  60. data/lib/psych/syntax_error.rb +21 -0
  61. data/lib/psych/tree_builder.rb +96 -0
  62. data/lib/psych/visitors.rb +6 -0
  63. data/lib/psych/visitors/depth_first.rb +26 -0
  64. data/lib/psych/visitors/emitter.rb +51 -0
  65. data/lib/psych/visitors/json_tree.rb +24 -0
  66. data/lib/psych/visitors/to_ruby.rb +372 -0
  67. data/lib/psych/visitors/visitor.rb +19 -0
  68. data/lib/psych/visitors/yaml_tree.rb +507 -0
  69. data/lib/psych/y.rb +9 -0
  70. data/test/psych/handlers/test_recorder.rb +25 -0
  71. data/test/psych/helper.rb +114 -0
  72. data/test/psych/json/test_stream.rb +109 -0
  73. data/test/psych/nodes/test_enumerable.rb +43 -0
  74. data/test/psych/test_alias_and_anchor.rb +96 -0
  75. data/test/psych/test_array.rb +57 -0
  76. data/test/psych/test_boolean.rb +36 -0
  77. data/test/psych/test_class.rb +36 -0
  78. data/test/psych/test_coder.rb +184 -0
  79. data/test/psych/test_date_time.rb +25 -0
  80. data/test/psych/test_deprecated.rb +214 -0
  81. data/test/psych/test_document.rb +46 -0
  82. data/test/psych/test_emitter.rb +94 -0
  83. data/test/psych/test_encoding.rb +254 -0
  84. data/test/psych/test_engine_manager.rb +47 -0
  85. data/test/psych/test_exception.rb +151 -0
  86. data/test/psych/test_hash.rb +44 -0
  87. data/test/psych/test_json_tree.rb +65 -0
  88. data/test/psych/test_merge_keys.rb +132 -0
  89. data/test/psych/test_nil.rb +18 -0
  90. data/test/psych/test_null.rb +19 -0
  91. data/test/psych/test_numeric.rb +45 -0
  92. data/test/psych/test_object.rb +44 -0
  93. data/test/psych/test_object_references.rb +67 -0
  94. data/test/psych/test_omap.rb +75 -0
  95. data/test/psych/test_parser.rb +339 -0
  96. data/test/psych/test_psych.rb +168 -0
  97. data/test/psych/test_safe_load.rb +97 -0
  98. data/test/psych/test_scalar.rb +11 -0
  99. data/test/psych/test_scalar_scanner.rb +106 -0
  100. data/test/psych/test_serialize_subclasses.rb +38 -0
  101. data/test/psych/test_set.rb +49 -0
  102. data/test/psych/test_stream.rb +93 -0
  103. data/test/psych/test_string.rb +153 -0
  104. data/test/psych/test_struct.rb +49 -0
  105. data/test/psych/test_symbol.rb +17 -0
  106. data/test/psych/test_tainted.rb +130 -0
  107. data/test/psych/test_to_yaml_properties.rb +63 -0
  108. data/test/psych/test_tree_builder.rb +79 -0
  109. data/test/psych/test_yaml.rb +1289 -0
  110. data/test/psych/test_yamldbm.rb +197 -0
  111. data/test/psych/test_yamlstore.rb +87 -0
  112. data/test/psych/visitors/test_depth_first.rb +49 -0
  113. data/test/psych/visitors/test_emitter.rb +144 -0
  114. data/test/psych/visitors/test_to_ruby.rb +326 -0
  115. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  116. metadata +257 -0
data/lib/psych.rb ADDED
@@ -0,0 +1,497 @@
1
+ require 'psych.so'
2
+ require 'psych/nodes'
3
+ require 'psych/streaming'
4
+ require 'psych/visitors'
5
+ require 'psych/handler'
6
+ require 'psych/tree_builder'
7
+ require 'psych/parser'
8
+ require 'psych/omap'
9
+ require 'psych/set'
10
+ require 'psych/coder'
11
+ require 'psych/core_ext'
12
+ require 'psych/deprecated'
13
+ require 'psych/stream'
14
+ require 'psych/json/tree_builder'
15
+ require 'psych/json/stream'
16
+ require 'psych/handlers/document_stream'
17
+
18
+ ###
19
+ # = Overview
20
+ #
21
+ # Psych is a YAML parser and emitter.
22
+ # Psych leverages libyaml [Home page: http://pyyaml.org/wiki/LibYAML]
23
+ # or [Git repo: https://github.com/zerotao/libyaml] for its YAML parsing
24
+ # and emitting capabilities. In addition to wrapping libyaml, Psych also
25
+ # knows how to serialize and de-serialize most Ruby objects to and from
26
+ # the YAML format.
27
+ #
28
+ # = I NEED TO PARSE OR EMIT YAML RIGHT NOW!
29
+ #
30
+ # # Parse some YAML
31
+ # Psych.load("--- foo") # => "foo"
32
+ #
33
+ # # Emit some YAML
34
+ # Psych.dump("foo") # => "--- foo\n...\n"
35
+ # { :a => 'b'}.to_yaml # => "---\n:a: b\n"
36
+ #
37
+ # Got more time on your hands? Keep on reading!
38
+ #
39
+ # == YAML Parsing
40
+ #
41
+ # Psych provides a range of interfaces for parsing a YAML document ranging from
42
+ # low level to high level, depending on your parsing needs. At the lowest
43
+ # level, is an event based parser. Mid level is access to the raw YAML AST,
44
+ # and at the highest level is the ability to unmarshal YAML to Ruby objects.
45
+ #
46
+ # == YAML Emitting
47
+ #
48
+ # Psych provides a range of interfaces ranging from low to high level for
49
+ # producing YAML documents. Very similar to the YAML parsing interfaces, Psych
50
+ # provides at the lowest level, an event based system, mid-level is building
51
+ # a YAML AST, and the highest level is converting a Ruby object straight to
52
+ # a YAML document.
53
+ #
54
+ # == High-level API
55
+ #
56
+ # === Parsing
57
+ #
58
+ # The high level YAML parser provided by Psych simply takes YAML as input and
59
+ # returns a Ruby data structure. For information on using the high level parser
60
+ # see Psych.load
61
+ #
62
+ # ==== Reading from a string
63
+ #
64
+ # Psych.load("--- a") # => 'a'
65
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
66
+ #
67
+ # ==== Reading from a file
68
+ #
69
+ # Psych.load_file("database.yml")
70
+ #
71
+ # ==== Exception handling
72
+ #
73
+ # begin
74
+ # # The second argument chnages only the exception contents
75
+ # Psych.parse("--- `", "file.txt")
76
+ # rescue Psych::SyntaxError => ex
77
+ # ex.file # => 'file.txt'
78
+ # ex.message # => "(file.txt): found character that cannot start any token"
79
+ # end
80
+ #
81
+ # === Emitting
82
+ #
83
+ # The high level emitter has the easiest interface. Psych simply takes a Ruby
84
+ # data structure and converts it to a YAML document. See Psych.dump for more
85
+ # information on dumping a Ruby data structure.
86
+ #
87
+ # ==== Writing to a string
88
+ #
89
+ # # Dump an array, get back a YAML string
90
+ # Psych.dump(['a', 'b']) # => "---\n- a\n- b\n"
91
+ #
92
+ # # Dump an array to an IO object
93
+ # Psych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
94
+ #
95
+ # # Dump an array with indentation set
96
+ # Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n- - b\n"
97
+ #
98
+ # # Dump an array to an IO with indentation set
99
+ # Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
100
+ #
101
+ # ==== Writing to a file
102
+ #
103
+ # Currently there is no direct API for dumping Ruby structure to file:
104
+ #
105
+ # File.open('database.yml', 'w') do |file|
106
+ # file.write(Psych.dump(['a', 'b']))
107
+ # end
108
+ #
109
+ # == Mid-level API
110
+ #
111
+ # === Parsing
112
+ #
113
+ # Psych provides access to an AST produced from parsing a YAML document. This
114
+ # tree is built using the Psych::Parser and Psych::TreeBuilder. The AST can
115
+ # be examined and manipulated freely. Please see Psych::parse_stream,
116
+ # Psych::Nodes, and Psych::Nodes::Node for more information on dealing with
117
+ # YAML syntax trees.
118
+ #
119
+ # ==== Reading from a string
120
+ #
121
+ # # Returns Psych::Nodes::Stream
122
+ # Psych.parse_stream("---\n - a\n - b")
123
+ #
124
+ # # Returns Psych::Nodes::Document
125
+ # Psych.parse("---\n - a\n - b")
126
+ #
127
+ # ==== Reading from a file
128
+ #
129
+ # # Returns Psych::Nodes::Stream
130
+ # Psych.parse_stream(File.read('database.yml'))
131
+ #
132
+ # # Returns Psych::Nodes::Document
133
+ # Psych.parse_file('database.yml')
134
+ #
135
+ # ==== Exception handling
136
+ #
137
+ # begin
138
+ # # The second argument chnages only the exception contents
139
+ # Psych.parse("--- `", "file.txt")
140
+ # rescue Psych::SyntaxError => ex
141
+ # ex.file # => 'file.txt'
142
+ # ex.message # => "(file.txt): found character that cannot start any token"
143
+ # end
144
+ #
145
+ # === Emitting
146
+ #
147
+ # At the mid level is building an AST. This AST is exactly the same as the AST
148
+ # used when parsing a YAML document. Users can build an AST by hand and the
149
+ # AST knows how to emit itself as a YAML document. See Psych::Nodes,
150
+ # Psych::Nodes::Node, and Psych::TreeBuilder for more information on building
151
+ # a YAML AST.
152
+ #
153
+ # ==== Writing to a string
154
+ #
155
+ # # We need Psych::Nodes::Stream (not Psych::Nodes::Document)
156
+ # stream = Psych.parse_stream("---\n - a\n - b")
157
+ #
158
+ # stream.to_yaml # => "---\n- a\n- b\n"
159
+ #
160
+ # ==== Writing to a file
161
+ #
162
+ # # We need Psych::Nodes::Stream (not Psych::Nodes::Document)
163
+ # stream = Psych.parse_stream(File.read('database.yml'))
164
+ #
165
+ # File.open('database.yml', 'w') do |file|
166
+ # file.write(stream.to_yaml)
167
+ # end
168
+ #
169
+ # == Low-level API
170
+ #
171
+ # === Parsing
172
+ #
173
+ # The lowest level parser should be used when the YAML input is already known,
174
+ # and the developer does not want to pay the price of building an AST or
175
+ # automatic detection and conversion to Ruby objects. See Psych::Parser for
176
+ # more information on using the event based parser.
177
+ #
178
+ # ==== Reading to Psych::Nodes::Stream structure
179
+ #
180
+ # parser = Psych::Parser.new(TreeBuilder.new) # => #<Psych::Parser>
181
+ # parser = Psych.parser # it's an alias for the above
182
+ #
183
+ # parser.parse("---\n - a\n - b") # => #<Psych::Parser>
184
+ # parser.handler # => #<Psych::TreeBuilder>
185
+ # parser.handler.root # => #<Psych::Nodes::Stream>
186
+ #
187
+ # ==== Receiving an events stream
188
+ #
189
+ # parser = Psych::Parser.new(Psych::Handlers::Recorder.new)
190
+ #
191
+ # parser.parse("---\n - a\n - b")
192
+ # parser.events # => [list of [event, args] lists]
193
+ # # event is one of: Psych::Handler::EVENTS
194
+ # # args are the arguments passed to the event
195
+ #
196
+ # === Emitting
197
+ #
198
+ # The lowest level emitter is an event based system. Events are sent to a
199
+ # Psych::Emitter object. That object knows how to convert the events to a YAML
200
+ # document. This interface should be used when document format is known in
201
+ # advance or speed is a concern. See Psych::Emitter for more information.
202
+ #
203
+ # ==== Writing to a Ruby structure
204
+ #
205
+ # Psych.parser.parse("--- a") # => #<Psych::Parser>
206
+ #
207
+ # parser.handler.first # => #<Psych::Nodes::Stream>
208
+ # parser.handler.first.to_ruby # => ["a"]
209
+ #
210
+ # parser.handler.root.first # => #<Psych::Nodes::Document>
211
+ # parser.handler.root.first.to_ruby # => "a"
212
+ #
213
+ # # You can instantiate an Emitter manually
214
+ # Psych::Visitors::ToRuby.new.accept(parser.handler.root.first)
215
+ # # => "a"
216
+
217
+ module Psych
218
+ # The version is Psych you're using
219
+ VERSION = '2.0.0'
220
+
221
+ # The version of libyaml Psych is using
222
+ LIBYAML_VERSION = Psych.libyaml_version.join '.'
223
+
224
+ ###
225
+ # Load +yaml+ in to a Ruby data structure. If multiple documents are
226
+ # provided, the object contained in the first document will be returned.
227
+ # +filename+ will be used in the exception message if any exception is raised
228
+ # while parsing.
229
+ #
230
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
231
+ #
232
+ # Example:
233
+ #
234
+ # Psych.load("--- a") # => 'a'
235
+ # Psych.load("---\n - a\n - b") # => ['a', 'b']
236
+ #
237
+ # begin
238
+ # Psych.load("--- `", "file.txt")
239
+ # rescue Psych::SyntaxError => ex
240
+ # ex.file # => 'file.txt'
241
+ # ex.message # => "(file.txt): found character that cannot start any token"
242
+ # end
243
+ def self.load yaml, filename = nil
244
+ result = parse(yaml, filename)
245
+ result ? result.to_ruby : result
246
+ end
247
+
248
+ ###
249
+ # Safely load the yaml string in +yaml+. By default, only the following
250
+ # classes are allowed to be deserialized:
251
+ #
252
+ # * TrueClass
253
+ # * FalseClass
254
+ # * NilClass
255
+ # * Numeric
256
+ # * String
257
+ # * Array
258
+ # * Hash
259
+ #
260
+ # Recursive data structures are not allowed by default. Arbitrary classes
261
+ # can be allowed by adding those classes to the +whitelist+. They are
262
+ # additive. For example, to allow Date deserialization:
263
+ #
264
+ # Psych.safe_load(yaml, [Date])
265
+ #
266
+ # Now the Date class can be loaded in addition to the classes listed above.
267
+ #
268
+ # Aliases can be explicitly allowed by changing the +aliases+ parameter.
269
+ # For example:
270
+ #
271
+ # x = []
272
+ # x << x
273
+ # yaml = Psych.dump x
274
+ # Psych.safe_load yaml # => raises an exception
275
+ # Psych.safe_load yaml, [], [], true # => loads the aliases
276
+ #
277
+ # A Psych::DisallowedClass exception will be raised if the yaml contains a
278
+ # class that isn't in the whitelist.
279
+ #
280
+ # A Psych::BadAlias exception will be raised if the yaml contains aliases
281
+ # but the +aliases+ parameter is set to false.
282
+ def self.safe_load yaml, whitelist_classes = [], whitelist_symbols = [], aliases = false, filename = nil
283
+ result = parse(yaml, filename)
284
+ return unless result
285
+
286
+ class_loader = ClassLoader::Restricted.new(whitelist_classes.map(&:to_s),
287
+ whitelist_symbols.map(&:to_s))
288
+ scanner = ScalarScanner.new class_loader
289
+ if aliases
290
+ visitor = Visitors::ToRuby.new scanner, class_loader
291
+ else
292
+ visitor = Visitors::NoAliasRuby.new scanner, class_loader
293
+ end
294
+ visitor.accept result
295
+ end
296
+
297
+ ###
298
+ # Parse a YAML string in +yaml+. Returns the Psych::Nodes::Document.
299
+ # +filename+ is used in the exception message if a Psych::SyntaxError is
300
+ # raised.
301
+ #
302
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
303
+ #
304
+ # Example:
305
+ #
306
+ # Psych.parse("---\n - a\n - b") # => #<Psych::Nodes::Document:0x00>
307
+ #
308
+ # begin
309
+ # Psych.parse("--- `", "file.txt")
310
+ # rescue Psych::SyntaxError => ex
311
+ # ex.file # => 'file.txt'
312
+ # ex.message # => "(file.txt): found character that cannot start any token"
313
+ # end
314
+ #
315
+ # See Psych::Nodes for more information about YAML AST.
316
+ def self.parse yaml, filename = nil
317
+ parse_stream(yaml, filename) do |node|
318
+ return node
319
+ end
320
+ false
321
+ end
322
+
323
+ ###
324
+ # Parse a file at +filename+. Returns the Psych::Nodes::Document.
325
+ #
326
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
327
+ def self.parse_file filename
328
+ File.open filename, 'r:bom|utf-8' do |f|
329
+ parse f, filename
330
+ end
331
+ end
332
+
333
+ ###
334
+ # Returns a default parser
335
+ def self.parser
336
+ Psych::Parser.new(TreeBuilder.new)
337
+ end
338
+
339
+ ###
340
+ # Parse a YAML string in +yaml+. Returns the Psych::Nodes::Stream.
341
+ # This method can handle multiple YAML documents contained in +yaml+.
342
+ # +filename+ is used in the exception message if a Psych::SyntaxError is
343
+ # raised.
344
+ #
345
+ # If a block is given, a Psych::Nodes::Document node will be yielded to the
346
+ # block as it's being parsed.
347
+ #
348
+ # Raises a Psych::SyntaxError when a YAML syntax error is detected.
349
+ #
350
+ # Example:
351
+ #
352
+ # Psych.parse_stream("---\n - a\n - b") # => #<Psych::Nodes::Stream:0x00>
353
+ #
354
+ # Psych.parse_stream("--- a\n--- b") do |node|
355
+ # node # => #<Psych::Nodes::Document:0x00>
356
+ # end
357
+ #
358
+ # begin
359
+ # Psych.parse_stream("--- `", "file.txt")
360
+ # rescue Psych::SyntaxError => ex
361
+ # ex.file # => 'file.txt'
362
+ # ex.message # => "(file.txt): found character that cannot start any token"
363
+ # end
364
+ #
365
+ # See Psych::Nodes for more information about YAML AST.
366
+ def self.parse_stream yaml, filename = nil, &block
367
+ if block_given?
368
+ parser = Psych::Parser.new(Handlers::DocumentStream.new(&block))
369
+ parser.parse yaml, filename
370
+ else
371
+ parser = self.parser
372
+ parser.parse yaml, filename
373
+ parser.handler.root
374
+ end
375
+ end
376
+
377
+ ###
378
+ # call-seq:
379
+ # Psych.dump(o) -> string of yaml
380
+ # Psych.dump(o, options) -> string of yaml
381
+ # Psych.dump(o, io) -> io object passed in
382
+ # Psych.dump(o, io, options) -> io object passed in
383
+ #
384
+ # Dump Ruby object +o+ to a YAML string. Optional +options+ may be passed in
385
+ # to control the output format. If an IO object is passed in, the YAML will
386
+ # be dumped to that IO object.
387
+ #
388
+ # Example:
389
+ #
390
+ # # Dump an array, get back a YAML string
391
+ # Psych.dump(['a', 'b']) # => "---\n- a\n- b\n"
392
+ #
393
+ # # Dump an array to an IO object
394
+ # Psych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
395
+ #
396
+ # # Dump an array with indentation set
397
+ # Psych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n- - b\n"
398
+ #
399
+ # # Dump an array to an IO with indentation set
400
+ # Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
401
+ def self.dump o, io = nil, options = {}
402
+ if Hash === io
403
+ options = io
404
+ io = nil
405
+ end
406
+
407
+ visitor = Psych::Visitors::YAMLTree.create options
408
+ visitor << o
409
+ visitor.tree.yaml io, options
410
+ end
411
+
412
+ ###
413
+ # Dump a list of objects as separate documents to a document stream.
414
+ #
415
+ # Example:
416
+ #
417
+ # Psych.dump_stream("foo\n ", {}) # => "--- ! \"foo\\n \"\n--- {}\n"
418
+ def self.dump_stream *objects
419
+ visitor = Psych::Visitors::YAMLTree.create({})
420
+ objects.each do |o|
421
+ visitor << o
422
+ end
423
+ visitor.tree.yaml
424
+ end
425
+
426
+ ###
427
+ # Dump Ruby +object+ to a JSON string.
428
+ def self.to_json object
429
+ visitor = Psych::Visitors::JSONTree.create
430
+ visitor << object
431
+ visitor.tree.yaml
432
+ end
433
+
434
+ ###
435
+ # Load multiple documents given in +yaml+. Returns the parsed documents
436
+ # as a list. If a block is given, each document will be converted to Ruby
437
+ # and passed to the block during parsing
438
+ #
439
+ # Example:
440
+ #
441
+ # Psych.load_stream("--- foo\n...\n--- bar\n...") # => ['foo', 'bar']
442
+ #
443
+ # list = []
444
+ # Psych.load_stream("--- foo\n...\n--- bar\n...") do |ruby|
445
+ # list << ruby
446
+ # end
447
+ # list # => ['foo', 'bar']
448
+ #
449
+ def self.load_stream yaml, filename = nil
450
+ if block_given?
451
+ parse_stream(yaml, filename) do |node|
452
+ yield node.to_ruby
453
+ end
454
+ else
455
+ parse_stream(yaml, filename).children.map { |child| child.to_ruby }
456
+ end
457
+ end
458
+
459
+ ###
460
+ # Load the document contained in +filename+. Returns the yaml contained in
461
+ # +filename+ as a Ruby object
462
+ def self.load_file filename
463
+ File.open(filename, 'r:bom|utf-8') { |f| self.load f, filename }
464
+ end
465
+
466
+ # :stopdoc:
467
+ @domain_types = {}
468
+ def self.add_domain_type domain, type_tag, &block
469
+ key = ['tag', domain, type_tag].join ':'
470
+ @domain_types[key] = [key, block]
471
+ @domain_types["tag:#{type_tag}"] = [key, block]
472
+ end
473
+
474
+ def self.add_builtin_type type_tag, &block
475
+ domain = 'yaml.org,2002'
476
+ key = ['tag', domain, type_tag].join ':'
477
+ @domain_types[key] = [key, block]
478
+ end
479
+
480
+ def self.remove_type type_tag
481
+ @domain_types.delete type_tag
482
+ end
483
+
484
+ @load_tags = {}
485
+ @dump_tags = {}
486
+ def self.add_tag tag, klass
487
+ @load_tags[tag] = klass.name
488
+ @dump_tags[klass] = tag
489
+ end
490
+
491
+ class << self
492
+ attr_accessor :load_tags
493
+ attr_accessor :dump_tags
494
+ attr_accessor :domain_types
495
+ end
496
+ # :startdoc:
497
+ end