Repository URL to install this package:
|
Version:
2.2.2-1 ▾
|
U:RDoc::NormalModule[iI"
Psych:EF@0o:RDoc::Markup::Document:@parts[(o;;[]S:RDoc::Markup::Heading:
leveli: textI"
Overview;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I")Psych is a YAML parser and emitter. ;TI"IPsych leverages libyaml [Home page: http://pyyaml.org/wiki/LibYAML] ;TI"Ior [HG repo: https://bitbucket.org/xi/libyaml] for its YAML parsing ;TI"Land emitting capabilities. In addition to wrapping libyaml, Psych also ;TI"Kknows how to serialize and de-serialize most Ruby objects to and from ;TI"the YAML format.;T@S; ;
i;I",I NEED TO PARSE OR EMIT YAML RIGHT NOW!;T@o:RDoc::Markup::Verbatim;[I"# Parse some YAML
;TI"&Psych.load("--- foo") # => "foo"
;TI"
;TI"# Emit some YAML
;TI"1Psych.dump("foo") # => "--- foo\n...\n"
;TI"/{ :a => 'b'}.to_yaml # => "---\n:a: b\n"
;T:@format0o;
;[I"3Got more time on your hands? Keep on reading!;T@S; ;
i;I"YAML Parsing;T@o;
;[ I"SPsych provides a range of interfaces for parsing a YAML document ranging from ;TI"Nlow level to high level, depending on your parsing needs. At the lowest ;TI"Plevel, is an event based parser. Mid level is access to the raw YAML AST, ;TI"Oand at the highest level is the ability to unmarshal YAML to Ruby objects.;T@S; ;
i;I"YAML Emitting;T@o;
;[
I"MPsych provides a range of interfaces ranging from low to high level for ;TI"Sproducing YAML documents. Very similar to the YAML parsing interfaces, Psych ;TI"Pprovides at the lowest level, an event based system, mid-level is building ;TI"Oa YAML AST, and the highest level is converting a Ruby object straight to ;TI"a YAML document.;T@S; ;
i;I"High-level API;T@S; ;
i;I"Parsing;T@o;
;[I"QThe high level YAML parser provided by Psych simply takes YAML as input and ;TI"Treturns a Ruby data structure. For information on using the high level parser ;TI"see Psych.load;T@S; ;
i ;I"Reading from a string;T@o;;[I".Psych.load("--- a") # => 'a'
;TI"5Psych.load("---\n - a\n - b") # => ['a', 'b']
;T;0S; ;
i ;I"Reading from a file;T@o;;[I"%Psych.load_file("database.yml")
;T;0S; ;
i ;I"Exception handling;T@o;;[I"begin
;TI"A # The second argument changes only the exception contents
;TI"( Psych.parse("--- `", "file.txt")
;TI"%rescue Psych::SyntaxError => ex
;TI"" ex.file # => 'file.txt'
;TI"Q ex.message # => "(file.txt): found character that cannot start any token"
;TI" end
;T;0S; ;
i;I"
Emitting;T@o;
;[I"RThe high level emitter has the easiest interface. Psych simply takes a Ruby ;TI"Qdata structure and converts it to a YAML document. See Psych.dump for more ;TI"2information on dumping a Ruby data structure.;T@S; ;
i ;I"Writing to a string;T@o;;[I"-# Dump an array, get back a YAML string
;TI"4Psych.dump(['a', 'b']) # => "---\n- a\n- b\n"
;TI"
;TI"%# Dump an array to an IO object
;TI"MPsych.dump(['a', 'b'], StringIO.new) # => #<StringIO:0x000001009d0890>
;TI"
;TI"*# Dump an array with indentation set
;TI"KPsych.dump(['a', ['b']], :indentation => 3) # => "---\n- a\n- - b\n"
;TI"
;TI"3# Dump an array to an IO with indentation set
;TI"?Psych.dump(['a', ['b']], StringIO.new, :indentation => 3)
;T;0S; ;
i ;I"Writing to a file;T@o;
;[I"ICurrently there is no direct API for dumping Ruby structure to file:;T@o;;[I".File.open('database.yml', 'w') do |file|
;TI"* file.write(Psych.dump(['a', 'b']))
;TI" end
;T;0S; ;
i;I"Mid-level API;T@S; ;
i;I"Parsing;T@o;
;[
I"RPsych provides access to an AST produced from parsing a YAML document. This ;TI"Ptree is built using the Psych::Parser and Psych::TreeBuilder. The AST can ;TI"Jbe examined and manipulated freely. Please see Psych::parse_stream, ;TI"OPsych::Nodes, and Psych::Nodes::Node for more information on dealing with ;TI"YAML syntax trees.;T@S; ;
i ;I"Reading from a string;T@o;;[
I"$# Returns Psych::Nodes::Stream
;TI"+Psych.parse_stream("---\n - a\n - b")
;TI"
;TI"&# Returns Psych::Nodes::Document
;TI"$Psych.parse("---\n - a\n - b")
;T;0S; ;
i ;I"Reading from a file;T@o;;[
I"$# Returns Psych::Nodes::Stream
;TI"3Psych.parse_stream(File.read('database.yml'))
;TI"
;TI"&# Returns Psych::Nodes::Document
;TI"&Psych.parse_file('database.yml')
;T;0S; ;
i ;I"Exception handling;T@o;;[I"begin
;TI"A # The second argument changes only the exception contents
;TI"( Psych.parse("--- `", "file.txt")
;TI"%rescue Psych::SyntaxError => ex
;TI"" ex.file # => 'file.txt'
;TI"Q ex.message # => "(file.txt): found character that cannot start any token"
;TI" end
;T;0S; ;
i;I"
Emitting;T@o;
;[
I"SAt the mid level is building an AST. This AST is exactly the same as the AST ;TI"Pused when parsing a YAML document. Users can build an AST by hand and the ;TI"IAST knows how to emit itself as a YAML document. See Psych::Nodes, ;TI"QPsych::Nodes::Node, and Psych::TreeBuilder for more information on building ;TI"a YAML AST.;T@S; ;
i ;I"Writing to a string;T@o;;[ I"A# We need Psych::Nodes::Stream (not Psych::Nodes::Document)
;TI"4stream = Psych.parse_stream("---\n - a\n - b")
;TI"
;TI"+stream.to_yaml # => "---\n- a\n- b\n"
;T;0S; ;
i ;I"Writing to a file;T@o;;[I"A# We need Psych::Nodes::Stream (not Psych::Nodes::Document)
;TI"<stream = Psych.parse_stream(File.read('database.yml'))
;TI"
;TI".File.open('database.yml', 'w') do |file|
;TI"" file.write(stream.to_yaml)
;TI" end
;T;0S; ;
i;I"Low-level API;T@S; ;
i;I"Parsing;T@o;
;[ I"RThe lowest level parser should be used when the YAML input is already known, ;TI"Land the developer does not want to pay the price of building an AST or ;TI"Pautomatic detection and conversion to Ruby objects. See Psych::Parser for ;TI"6more information on using the event based parser.;T@S; ;
i ;I".Reading to Psych::Nodes::Stream structure;T@o;;[I"Gparser = Psych::Parser.new(TreeBuilder.new) # => #<Psych::Parser>
;TI"Oparser = Psych.parser # it's an alias for the above
;TI"
;TI"Gparser.parse("---\n - a\n - b") # => #<Psych::Parser>
;TI"Lparser.handler # => #<Psych::TreeBuilder>
;TI"Nparser.handler.root # => #<Psych::Nodes::Stream>
;T;0S; ;
i ;I"Receiving an events stream;T@o;;[I"?parser = Psych::Parser.new(Psych::Handlers::Recorder.new)
;TI"
;TI"%parser.parse("---\n - a\n - b")
;TI"6parser.events # => [list of [event, args] lists]
;TI"= # event is one of: Psych::Handler::EVENTS
;TI"@ # args are the arguments passed to the event
;T;0S; ;
i;I"
Emitting;T@o;
;[ I"NThe lowest level emitter is an event based system. Events are sent to a ;TI"SPsych::Emitter object. That object knows how to convert the events to a YAML ;TI"Odocument. This interface should be used when document format is known in ;TI"Madvance or speed is a concern. See Psych::Emitter for more information.;T@S; ;
i ;I" Writing to a Ruby structure;T@o;;[I"=Psych.parser.parse("--- a") # => #<Psych::Parser>
;TI"
;TI"Dparser.handler.first # => #<Psych::Nodes::Stream>
;TI"2parser.handler.first.to_ruby # => ["a"]
;TI"
;TI"Fparser.handler.root.first # => #<Psych::Nodes::Document>
;TI"0parser.handler.root.first.to_ruby # => "a"
;TI"
;TI"/# You can instantiate an Emitter manually
;TI"CPsych::Visitors::ToRuby.new.accept(parser.handler.root.first)
;TI"
# => "a";T;0:
@fileI"ext/psych/lib/psych.rb;T:0@omit_headings_from_table_of_contents_below0o;;[ ;I"(ext/psych/lib/psych/class_loader.rb;T;0o;;[ ;I"!ext/psych/lib/psych/coder.rb;T;0o;;[ ;I"&ext/psych/lib/psych/deprecated.rb;T;0o;;[ ;I"%ext/psych/lib/psych/exception.rb;T;0o;;[ ;I"#ext/psych/lib/psych/handler.rb;T;0o;;[ ;I"4ext/psych/lib/psych/handlers/document_stream.rb;T;0o;;[ ;I"-ext/psych/lib/psych/handlers/recorder.rb;T;0o;;[ ;I",ext/psych/lib/psych/json/ruby_events.rb;T;0o;;[ ;I"'ext/psych/lib/psych/json/stream.rb;T;0o;;[ ;I"-ext/psych/lib/psych/json/tree_builder.rb;T;0o;;[ ;I",ext/psych/lib/psych/json/yaml_events.rb;T;0o;;[ ;I"!ext/psych/lib/psych/nodes.rb;T;0o;;[ ;I"'ext/psych/lib/psych/nodes/alias.rb;T;0o;;[ ;I"*ext/psych/lib/psych/nodes/document.rb;T;0o;;[ ;I")ext/psych/lib/psych/nodes/mapping.rb;T;0o;;[ ;I"&ext/psych/lib/psych/nodes/node.rb;T;0o;;[ ;I"(ext/psych/lib/psych/nodes/scalar.rb;T;0o;;[ ;I"*ext/psych/lib/psych/nodes/sequence.rb;T;0o;;[ ;I"(ext/psych/lib/psych/nodes/stream.rb;T;0o;;[ ;I" ext/psych/lib/psych/omap.rb;T;0o;;[ ;I""ext/psych/lib/psych/parser.rb;T;0o;;[ ;I"*ext/psych/lib/psych/scalar_scanner.rb;T;0o;;[ ;I"ext/psych/lib/psych/set.rb;T;0o;;[ ;I""ext/psych/lib/psych/stream.rb;T;0o;;[ ;I"%ext/psych/lib/psych/streaming.rb;T;0o;;[ ;I"(ext/psych/lib/psych/syntax_error.rb;T;0o;;[ ;I"(ext/psych/lib/psych/tree_builder.rb;T;0o;;[ ;I"0ext/psych/lib/psych/visitors/depth_first.rb;T;0o;;[ ;I",ext/psych/lib/psych/visitors/emitter.rb;T;0o;;[ ;I".ext/psych/lib/psych/visitors/json_tree.rb;T;0o;;[ ;I",ext/psych/lib/psych/visitors/to_ruby.rb;T;0o;;[ ;I",ext/psych/lib/psych/visitors/visitor.rb;T;0o;;[ ;I".ext/psych/lib/psych/visitors/yaml_tree.rb;T;0o;;[ ;I"ext/psych/psych.c;T;0;0;0[ [U:RDoc::Constant[i I"VERSION;FI"Psych::VERSION;F00o;;[o;
;[I"&The version is Psych you're using;T;@ç;0@ç@cRDoc::NormalModule0U;[i I"LIBYAML_VERSION;FI"Psych::LIBYAML_VERSION;F00o;;[o;
;[I"*The version of libyaml Psych is using;T;@ç;0@ç@@Y0[ [[I"
class;T[[:public[[I"add_private_type;FI"&ext/psych/lib/psych/deprecated.rb;T[I"add_ruby_type;F@l[I"detect_implicit;F@l[I" dump;FI"ext/psych/lib/psych.rb;T[I"dump_stream;F@s[I"libyaml_version;TI"ext/psych/psych.c;T[I" load;F@s[I"load_documents;F@l[I"load_file;F@s[I"load_stream;F@s[I"object_maker;F@l[I"
parse;F@s[I"parse_file;F@s[I"parse_stream;F@s[I"parser;F@s[I"read_type_class;F@l[I"safe_load;F@s[I"
tagurize;F@l[I"to_json;F@s[:protected[ [:private[ [I"
instance;T[[;[ [;[ [;[ [[I"DeprecatedMethods;To;;[ ;@ð;0@l[U:RDoc::Context::Section[i 0o;;[ ;0;0[-@ç@ê@í@ð@ó@ö@ù@ü@ÿ@@@@@@@@@@@ @#@&@)@,@/@2@5@8@;@>@A@D@G@J@MI"lib/rdoc/rdoc.rb;TI" lib/rubygems/config_file.rb;TI"$lib/rubygems/psych_additions.rb;TI"lib/rubygems/psych_tree.rb;TI""lib/rubygems/specification.rb;T@cRDoc::TopLevel