aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/hash/conversions.rb
diff options
context:
space:
mode:
authorJosh Franklin <contact@sentaidigital.com>2010-03-26 12:43:59 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-26 12:44:12 +0100
commitc7cc9583689d63d342983d739ccf5c4e94233a48 (patch)
tree8094fd1816e900b675ccd50d89de16c8df4ac71a /activesupport/lib/active_support/core_ext/hash/conversions.rb
parent4c7c4061558bb8781da0d54159e3cebcb0a8c07a (diff)
downloadrails-c7cc9583689d63d342983d739ccf5c4e94233a48.tar.gz
rails-c7cc9583689d63d342983d739ccf5c4e94233a48.tar.bz2
rails-c7cc9583689d63d342983d739ccf5c4e94233a48.zip
Add support for a type=binary with an optional encoding=base64. If the encoding attribute is absent, the data is considered unencoded.
[#2966 state:resolved]
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/conversions.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb
index 48b185d05e..c882434f78 100644
--- a/activesupport/lib/active_support/core_ext/hash/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb
@@ -54,6 +54,15 @@ class Hash
"string" => Proc.new { |string| string.to_s },
"yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
"base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
+ "binary" => Proc.new do |bin, entity|
+ case entity['encoding']
+ when 'base64'
+ ActiveSupport::Base64.decode64(bin)
+ # TODO: Add support for other encodings
+ else
+ bin
+ end
+ end,
"file" => Proc.new do |file, entity|
f = StringIO.new(ActiveSupport::Base64.decode64(file))
f.extend(FileLike)