diff options
Diffstat (limited to 'activesupport/lib/active_support/json/decoding.rb')
-rw-r--r-- | activesupport/lib/active_support/json/decoding.rb | 17 |
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 |