* ext/syck/lib/yaml/syck.rb: split from ext/syck/lib/syck.rb for
backward compatibility. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27334 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bde213674c
commit
eedb41a85b
@ -1,3 +1,8 @@
|
|||||||
|
Wed Apr 14 11:37:52 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* ext/syck/lib/yaml/syck.rb: split from ext/syck/lib/syck.rb for
|
||||||
|
backward compatibility.
|
||||||
|
|
||||||
Wed Apr 14 09:24:07 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Wed Apr 14 09:24:07 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* ext/nkf/nkf-utf8/nkf.c: Refix [nkf-bug:21393]. (explicit -X)
|
* ext/nkf/nkf-utf8/nkf.c: Refix [nkf-bug:21393]. (explicit -X)
|
||||||
|
@ -6,13 +6,7 @@
|
|||||||
# Author:: why the lucky stiff
|
# Author:: why the lucky stiff
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'stringio'
|
require 'yaml/syck'
|
||||||
require 'syck.so'
|
|
||||||
require 'syck/error'
|
|
||||||
require 'syck/syck'
|
|
||||||
require 'syck/tag'
|
|
||||||
require 'syck/stream'
|
|
||||||
require 'syck/constants'
|
|
||||||
|
|
||||||
# == YAML
|
# == YAML
|
||||||
#
|
#
|
||||||
@ -108,8 +102,8 @@ module Syck
|
|||||||
Emitter.new.set_resolver( self.resolver )
|
Emitter.new.set_resolver( self.resolver )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Converts _obj_ to YAML and writes the YAML result to _io_.
|
# Converts _obj_ to YAML and writes the YAML result to _io_.
|
||||||
#
|
#
|
||||||
# File.open( 'animals.yaml', 'w' ) do |out|
|
# File.open( 'animals.yaml', 'w' ) do |out|
|
||||||
# YAML.dump( ['badger', 'elephant', 'tiger'], out )
|
# YAML.dump( ['badger', 'elephant', 'tiger'], out )
|
||||||
@ -117,18 +111,18 @@ module Syck
|
|||||||
#
|
#
|
||||||
# If no _io_ is provided, a string containing the dumped YAML
|
# If no _io_ is provided, a string containing the dumped YAML
|
||||||
# is returned.
|
# is returned.
|
||||||
#
|
#
|
||||||
# YAML.dump( :locked )
|
# YAML.dump( :locked )
|
||||||
# #=> "--- :locked"
|
# #=> "--- :locked"
|
||||||
#
|
#
|
||||||
def self.dump( obj, io = nil )
|
def self.dump( obj, io = nil )
|
||||||
obj.to_yaml( io || io2 = StringIO.new )
|
obj.to_yaml( io || io2 = StringIO.new )
|
||||||
io || ( io2.rewind; io2.read )
|
io || ( io2.rewind; io2.read )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load a document from the current _io_ stream.
|
# Load a document from the current _io_ stream.
|
||||||
#
|
#
|
||||||
# File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) }
|
# File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) }
|
||||||
# #=> ['badger', 'elephant', 'tiger']
|
# #=> ['badger', 'elephant', 'tiger']
|
||||||
#
|
#
|
||||||
@ -137,9 +131,9 @@ module Syck
|
|||||||
# YAML.load( "--- :locked" )
|
# YAML.load( "--- :locked" )
|
||||||
# #=> :locked
|
# #=> :locked
|
||||||
#
|
#
|
||||||
def self.load( io )
|
def self.load( io )
|
||||||
yp = parser.load( io )
|
yp = parser.load( io )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Load a document from the file located at _filepath_.
|
# Load a document from the file located at _filepath_.
|
||||||
@ -153,9 +147,9 @@ module Syck
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse the first document from the current _io_ stream
|
# Parse the first document from the current _io_ stream
|
||||||
#
|
#
|
||||||
# File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) }
|
# File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) }
|
||||||
# #=> #<YAML::Syck::Node:0x82ccce0
|
# #=> #<YAML::Syck::Node:0x82ccce0
|
||||||
# @kind=:seq,
|
# @kind=:seq,
|
||||||
@ -180,9 +174,9 @@ module Syck
|
|||||||
# @type_id="tag:ruby.yaml.org,2002:sym",
|
# @type_id="tag:ruby.yaml.org,2002:sym",
|
||||||
# @value=":locked", @kind=:scalar>
|
# @value=":locked", @kind=:scalar>
|
||||||
#
|
#
|
||||||
def self.parse( io )
|
def self.parse( io )
|
||||||
yp = generic_parser.load( io )
|
yp = generic_parser.load( io )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse a document from the file located at _filepath_.
|
# Parse a document from the file located at _filepath_.
|
||||||
@ -210,8 +204,8 @@ module Syck
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Calls _block_ with each consecutive document in the YAML
|
# Calls _block_ with each consecutive document in the YAML
|
||||||
# stream contained in _io_.
|
# stream contained in _io_.
|
||||||
#
|
#
|
||||||
# File.open( 'many-docs.yaml' ) do |yf|
|
# File.open( 'many-docs.yaml' ) do |yf|
|
||||||
@ -220,14 +214,14 @@ module Syck
|
|||||||
# ## from the YAML document
|
# ## from the YAML document
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.each_document( io, &block )
|
def self.each_document( io, &block )
|
||||||
warn "#{caller[0]}: YAML.each_document is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.each_document is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
yp = parser.load_documents( io, &block )
|
yp = parser.load_documents( io, &block )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Calls _block_ with each consecutive document in the YAML
|
# Calls _block_ with each consecutive document in the YAML
|
||||||
# stream contained in _io_.
|
# stream contained in _io_.
|
||||||
#
|
#
|
||||||
# File.open( 'many-docs.yaml' ) do |yf|
|
# File.open( 'many-docs.yaml' ) do |yf|
|
||||||
@ -236,13 +230,13 @@ module Syck
|
|||||||
# ## from the YAML document
|
# ## from the YAML document
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.load_documents( io, &doc_proc )
|
def self.load_documents( io, &doc_proc )
|
||||||
yp = parser.load_documents( io, &doc_proc )
|
yp = parser.load_documents( io, &doc_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Calls _block_ with a tree of +YAML::BaseNodes+, one tree for
|
# Calls _block_ with a tree of +YAML::BaseNodes+, one tree for
|
||||||
# each consecutive document in the YAML stream contained in _io_.
|
# each consecutive document in the YAML stream contained in _io_.
|
||||||
#
|
#
|
||||||
# File.open( 'many-docs.yaml' ) do |yf|
|
# File.open( 'many-docs.yaml' ) do |yf|
|
||||||
@ -251,14 +245,14 @@ module Syck
|
|||||||
# ## from the YAML document
|
# ## from the YAML document
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.each_node( io, &doc_proc )
|
def self.each_node( io, &doc_proc )
|
||||||
warn "#{caller[0]}: YAML.each_node is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.each_node is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
yp = generic_parser.load_documents( io, &doc_proc )
|
yp = generic_parser.load_documents( io, &doc_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Calls _block_ with a tree of +YAML::BaseNodes+, one tree for
|
# Calls _block_ with a tree of +YAML::BaseNodes+, one tree for
|
||||||
# each consecutive document in the YAML stream contained in _io_.
|
# each consecutive document in the YAML stream contained in _io_.
|
||||||
#
|
#
|
||||||
# File.open( 'many-docs.yaml' ) do |yf|
|
# File.open( 'many-docs.yaml' ) do |yf|
|
||||||
@ -267,27 +261,27 @@ module Syck
|
|||||||
# ## from the YAML document
|
# ## from the YAML document
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
def self.parse_documents( io, &doc_proc )
|
def self.parse_documents( io, &doc_proc )
|
||||||
warn "#{caller[0]}: YAML.parse_documents is deprecated, use load_stream" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.parse_documents is deprecated, use load_stream" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
self.each_node( io, &doc_proc )
|
self.each_node( io, &doc_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Loads all documents from the current _io_ stream,
|
# Loads all documents from the current _io_ stream,
|
||||||
# returning a +YAML::Stream+ object containing all
|
# returning a +YAML::Stream+ object containing all
|
||||||
# loaded documents.
|
# loaded documents.
|
||||||
#
|
#
|
||||||
def self.load_stream( io )
|
def self.load_stream( io )
|
||||||
d = nil
|
d = nil
|
||||||
parser.load_documents( io ) do |doc|
|
parser.load_documents( io ) do |doc|
|
||||||
d = Stream.new if not d
|
d = Stream.new if not d
|
||||||
d.add( doc )
|
d.add( doc )
|
||||||
end
|
end
|
||||||
return d
|
return d
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a YAML stream containing each of the items in +objs+,
|
# Returns a YAML stream containing each of the items in +objs+,
|
||||||
# each having their own document.
|
# each having their own document.
|
||||||
#
|
#
|
||||||
@ -296,43 +290,43 @@ module Syck
|
|||||||
# --- []
|
# --- []
|
||||||
# --- {}
|
# --- {}
|
||||||
#
|
#
|
||||||
def self.dump_stream( *objs )
|
def self.dump_stream( *objs )
|
||||||
d = Stream.new
|
d = Stream.new
|
||||||
objs.each do |doc|
|
objs.each do |doc|
|
||||||
d.add( doc )
|
d.add( doc )
|
||||||
end
|
end
|
||||||
d.emit
|
d.emit
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add a global handler for a YAML domain type.
|
# Add a global handler for a YAML domain type.
|
||||||
#
|
#
|
||||||
def self.add_domain_type( domain, type_tag, &transfer_proc )
|
def self.add_domain_type( domain, type_tag, &transfer_proc )
|
||||||
resolver.add_type( "tag:#{ domain }:#{ type_tag }", transfer_proc )
|
resolver.add_type( "tag:#{ domain }:#{ type_tag }", transfer_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add a transfer method for a builtin type
|
# Add a transfer method for a builtin type
|
||||||
#
|
#
|
||||||
def self.add_builtin_type( type_tag, &transfer_proc )
|
def self.add_builtin_type( type_tag, &transfer_proc )
|
||||||
resolver.add_type( "tag:yaml.org,2002:#{ type_tag }", transfer_proc )
|
resolver.add_type( "tag:yaml.org,2002:#{ type_tag }", transfer_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add a transfer method for a builtin type
|
# Add a transfer method for a builtin type
|
||||||
#
|
#
|
||||||
def self.add_ruby_type( type_tag, &transfer_proc )
|
def self.add_ruby_type( type_tag, &transfer_proc )
|
||||||
warn "#{caller[0]}: YAML.add_ruby_type is deprecated, use add_domain_type" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.add_ruby_type is deprecated, use add_domain_type" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
resolver.add_type( "tag:ruby.yaml.org,2002:#{ type_tag }", transfer_proc )
|
resolver.add_type( "tag:ruby.yaml.org,2002:#{ type_tag }", transfer_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Add a private document type
|
# Add a private document type
|
||||||
#
|
#
|
||||||
def self.add_private_type( type_re, &transfer_proc )
|
def self.add_private_type( type_re, &transfer_proc )
|
||||||
warn "#{caller[0]}: YAML.add_private_type is deprecated, use add_domain_type" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.add_private_type is deprecated, use add_domain_type" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
resolver.add_type( "x-private:" + type_re, transfer_proc )
|
resolver.add_type( "x-private:" + type_re, transfer_proc )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Detect typing of a string
|
# Detect typing of a string
|
||||||
@ -358,13 +352,13 @@ module Syck
|
|||||||
resolver.transfer( tagurize( type_id ), obj )
|
resolver.transfer( tagurize( type_id ), obj )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Apply any implicit a node may qualify for
|
# Apply any implicit a node may qualify for
|
||||||
#
|
#
|
||||||
def self.try_implicit( obj )
|
def self.try_implicit( obj )
|
||||||
warn "#{caller[0]}: YAML.try_implicit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.try_implicit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
transfer( detect_implicit( obj ), obj )
|
transfer( detect_implicit( obj ), obj )
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Method to extract colon-seperated type and class, returning
|
# Method to extract colon-seperated type and class, returning
|
||||||
@ -393,10 +387,10 @@ module Syck
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Allocate an Emitter if needed
|
# Allocate an Emitter if needed
|
||||||
#
|
#
|
||||||
def self.quick_emit( oid, opts = {}, &e )
|
def self.quick_emit( oid, opts = {}, &e )
|
||||||
warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
warn "#{caller[0]}: YAML.quick_emit is deprecated" if $VERBOSE && !caller[0].start_with?(File.dirname(__FILE__))
|
||||||
out =
|
out =
|
||||||
if opts.is_a? Emitter
|
if opts.is_a? Emitter
|
||||||
@ -405,13 +399,10 @@ module Syck
|
|||||||
emitter.reset( opts )
|
emitter.reset( opts )
|
||||||
end
|
end
|
||||||
out.emit( oid, &e )
|
out.emit( oid, &e )
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'syck/rubytypes'
|
|
||||||
require 'syck/types'
|
|
||||||
|
|
||||||
module Kernel
|
module Kernel
|
||||||
#
|
#
|
||||||
# ryan:: You know how Kernel.p is a really convenient way to dump ruby
|
# ryan:: You know how Kernel.p is a really convenient way to dump ruby
|
||||||
|
14
ext/syck/lib/yaml/syck.rb
Normal file
14
ext/syck/lib/yaml/syck.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# $Id$
|
||||||
|
#
|
||||||
|
# = yaml/syck.rb:
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'stringio'
|
||||||
|
require 'syck.so'
|
||||||
|
require 'syck/error'
|
||||||
|
require 'syck/syck'
|
||||||
|
require 'syck/tag'
|
||||||
|
require 'syck/stream'
|
||||||
|
require 'syck/constants'
|
||||||
|
require 'syck/rubytypes'
|
||||||
|
require 'syck/types'
|
Loading…
x
Reference in New Issue
Block a user