summaryrefslogtreecommitdiff
path: root/lib/yaml.rb
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-11 22:52:14 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-11 22:52:14 +0000
commita1e257ec48911d3ca1aaeda0127061c244f36147 (patch)
treeb77a31d1f26f6f313ee33af850fc539a6e149f39 /lib/yaml.rb
parent30399f6c758c85ac9794d4298ee2b51426a144bc (diff)
downloadruby-a1e257ec48911d3ca1aaeda0127061c244f36147.tar.gz
* ext/syck/emitter.c: new emitter code.
* ext/syck/rubyext.c: Emitter class. * lib/yaml.rb: Load Syck emitter, if available. * lib/yaml/stream.rb: ditto. * lib/yaml/baseemitter.rb: underlying class for all emitters. * lib/yaml/rubytypes.rb: use BaseEmitter abstraction. * lib/yaml/emitter.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/yaml.rb')
-rw-r--r--lib/yaml.rb37
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb
index 39e176541e..d33f2e202a 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -12,18 +12,29 @@ module YAML
require 'yaml/syck'
@@parser = YAML::Syck::Parser
@@loader = YAML::Syck::DefaultLoader
+ @@emitter = YAML::Syck::Emitter
rescue LoadError
require 'yaml/parser'
@@parser = YAML::Parser
@@loader = YAML::DefaultLoader
+ require 'yaml/emitter'
+ @@emitter = YAML::Emitter
end
- require 'yaml/emitter'
require 'yaml/loader'
require 'yaml/stream'
#
# Load a single document from the current stream
#
+ def YAML.dump( obj, io = nil )
+ io ||= ""
+ io << obj.to_yaml
+ io
+ end
+
+ #
+ # Load a single document from the current stream
+ #
def YAML.load( io )
yp = @@parser.new.load( io )
end
@@ -158,6 +169,30 @@ module YAML
end
end
+ #
+ # Allocate an Emitter if needed
+ #
+ def YAML.quick_emit( oid, opts = {}, &e )
+ old_opt = nil
+ if opts[:Emitter].is_a? @@emitter
+ out = opts.delete( :Emitter )
+ old_opt = out.options.dup
+ out.options.update( opts )
+ else
+ out = @@emitter.new( opts )
+ end
+ aidx = out.start_object( oid )
+ if aidx
+ out.simple( "*#{ aidx }" )
+ else
+ e.call( out )
+ end
+ if old_opt.is_a? Hash
+ out.options = old_opt
+ end
+ out.end_object
+ end
+
end
require 'yaml/rubytypes'