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