Skip to content
Browse files

load the JSON Backend lazily.

  • Loading branch information...
1 parent 5b80ead commit 2b5e4f38f5d7af912770f8a298ba2e5788c715b1 @technoweenie technoweenie committed May 17, 2009
View
11 activesupport/lib/active_support/json.rb
@@ -36,9 +36,15 @@ def self.escape(string)
end
class << self
- attr_reader :backend
delegate :decode, :to => :backend
-
+
+ def backend
+ @backend || begin
+ self.backend = "Yaml"
+ @backend
+ end
+ end
+
def backend=(name)
if name.is_a?(Module)
@backend = name
@@ -73,6 +79,5 @@ def escape_html_entities_in_json=(value)
end
ActiveSupport.escape_html_entities_in_json = true
-ActiveSupport::JSON.backend = 'Yaml'
require 'active_support/json/encoding'
View
4 activesupport/lib/active_support/json/backends/jsongem.rb
@@ -1,6 +1,8 @@
+require 'json' unless defined?(JSON)
+
module ActiveSupport
module JSON
- ParseError = ::JSON::ParserError
+ ParseError = ::JSON::ParserError unless const_defined?(:ParseError)
module Backends
module JSONGem
View
4 activesupport/lib/active_support/json/backends/yaml.rb
@@ -2,7 +2,9 @@
module ActiveSupport
module JSON
- class ParseError < StandardError
+ unless const_defined?(:ParseError)
+ class ParseError < StandardError
+ end
end
module Backends
View
3 activesupport/test/json/decoding_test.rb
@@ -34,6 +34,9 @@ class TestJSONDecoding < ActiveSupport::TestCase
%q({"b":["\u003ci\u003e","\u003cb\u003e","\u003cu\u003e"]}) => {'b' => ["<i>","<b>","<u>"]}
}
+ # load the default JSON backend
+ ActiveSupport::JSON.backend
+
backends = %w(Yaml)
begin
gem 'json', '>= 1.1'

0 comments on commit 2b5e4f3

Please sign in to comment.
Something went wrong with that request. Please try again.