diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-04 14:09:35 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-04 15:07:15 -0800 |
commit | a84b84efaca02a0164c32a10df59f581eef16ac8 (patch) | |
tree | 8918e687fde521f4f9f02d308ccca9c344828f8f | |
parent | b1dc9c004e0e81fe69416c117bcc04d2cbd2c83c (diff) | |
download | rails-a84b84efaca02a0164c32a10df59f581eef16ac8.tar.gz rails-a84b84efaca02a0164c32a10df59f581eef16ac8.tar.bz2 rails-a84b84efaca02a0164c32a10df59f581eef16ac8.zip |
require Psych if possible, use Psych output when enabled
-rw-r--r-- | activesupport/lib/active_support/ordered_hash.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 8e157d3af4..ac20988230 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -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 |