aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/ordered_hash.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-01-04 14:09:35 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-04 15:07:15 -0800
commita84b84efaca02a0164c32a10df59f581eef16ac8 (patch)
tree8918e687fde521f4f9f02d308ccca9c344828f8f /activesupport/lib/active_support/ordered_hash.rb
parentb1dc9c004e0e81fe69416c117bcc04d2cbd2c83c (diff)
downloadrails-a84b84efaca02a0164c32a10df59f581eef16ac8.tar.gz
rails-a84b84efaca02a0164c32a10df59f581eef16ac8.tar.bz2
rails-a84b84efaca02a0164c32a10df59f581eef16ac8.zip
require Psych if possible, use Psych output when enabled
Diffstat (limited to 'activesupport/lib/active_support/ordered_hash.rb')
-rw-r--r--activesupport/lib/active_support/ordered_hash.rb15
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