aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json/decoding.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-02-14 19:28:05 +0000
committerPratik Naik <pratiknaik@gmail.com>2010-02-14 19:28:05 +0000
commit6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3 (patch)
tree3da8d75101aabe3c1d90d0582505ec1480c9d885 /activesupport/lib/active_support/json/decoding.rb
parent77bf78b3b78a41d4f2f6e733f5c9c00608c0adba (diff)
parenta1b60696e2b13cbe94d748444cc0da37b190fbb8 (diff)
downloadrails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.tar.gz
rails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.tar.bz2
rails-6f3c5f67870a625b8be4de6e34e8d0d2f5d2b5e3.zip
Merge remote branch 'mainstream/master'
Conflicts: railties/README railties/guides/source/active_support_core_extensions.textile railties/guides/source/getting_started.textile railties/lib/generators/rails/app/templates/README
Diffstat (limited to 'activesupport/lib/active_support/json/decoding.rb')
-rw-r--r--activesupport/lib/active_support/json/decoding.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index a5908365af..e357b6837a 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -6,12 +6,15 @@ module ActiveSupport
mattr_accessor :parse_json_times
module JSON
+ # Listed in order of preference.
+ DECODERS = %w(Yajl JSONGem Yaml)
+
class << self
attr_reader :parse_error
delegate :decode, :to => :backend
def backend
- self.backend = "Yaml" unless defined?(@backend)
+ set_default_backend unless defined?(@backend)
@backend
end
@@ -31,6 +34,18 @@ module ActiveSupport
ensure
self.backend = old_backend
end
+
+ def set_default_backend
+ DECODERS.find do |name|
+ begin
+ self.backend = name
+ true
+ rescue LoadError
+ # Try next decoder.
+ false
+ end
+ end
+ end
end
end
end