diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-18 07:30:09 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-18 07:30:09 +0000 |
commit | 27ba5edef1c4264a8d1c0e54675723d37a391dd8 (patch) | |
tree | 83e5292708b2452b26d92f4a95dd6094f298c64e /activesupport/lib/active_support/core_ext/hash | |
parent | 3202fbabe6df3591d7e2c35727ea9c8b68df8828 (diff) | |
download | rails-27ba5edef1c4264a8d1c0e54675723d37a391dd8.tar.gz rails-27ba5edef1c4264a8d1c0e54675723d37a391dd8.tar.bz2 rails-27ba5edef1c4264a8d1c0e54675723d37a391dd8.zip |
Hash#to_xml supports YAML attributes; ActiveRecord::Base#to_xml support serialized attributes. Closes #7502.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6444 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/conversions.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index f0ce27508f..bbfc2502a1 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -38,7 +38,8 @@ module ActiveSupport #:nodoc: XML_FORMATTING = { "date" => Proc.new { |date| date.to_s(:db) }, "datetime" => Proc.new { |time| time.xmlschema }, - "binary" => Proc.new { |binary| Base64.encode64(binary) } + "binary" => Proc.new { |binary| Base64.encode64(binary) }, + "yaml" => Proc.new { |yaml| yaml.to_yaml } } unless defined? XML_FORMATTING def self.included(klass) @@ -105,7 +106,7 @@ module ActiveSupport #:nodoc: module ClassMethods def from_xml(xml) # TODO: Refactor this into something much cleaner that doesn't rely on XmlSimple - undasherize_keys(typecast_xml_value(XmlSimple.xml_in(xml, + typecast_xml_value(undasherize_keys(XmlSimple.xml_in(xml, 'forcearray' => false, 'forcecontent' => true, 'keeproot' => true, @@ -129,6 +130,7 @@ module ActiveSupport #:nodoc: when "boolean" then content.strip == "true" when "datetime" then ::Time.parse(content).utc when "date" then ::Date.parse(content) + when "yaml" then YAML::load(content) rescue content else content end else |