require Psych if possible, use Psych output when enabled

This commit is contained in:
Aaron Patterson
2011-01-04 14:09:35 -08:00
parent b1dc9c004e
commit a84b84efac

View File

@@ -1,3 +1,8 @@
begin
require 'psych'
rescue LoadError
end
require 'yaml'
YAML.add_builtin_type("omap") do |type, val|
@@ -20,9 +25,17 @@ module ActiveSupport
"!tag:yaml.org,2002:omap"
end
def encode_with(coder)
coder.represent_seq '!omap', map { |k,v| { k => v } }
end
def to_yaml(opts = {})
if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
return super
end
YAML.quick_emit(self, opts) do |out|
out.seq(taguri, to_yaml_style) do |seq|
out.seq(taguri) do |seq|
each do |k, v|
seq.add(k => v)
end