load the JSON Backend lazily. If the JSON gem is already loaded, use the JSONGem backend by default.
This commit is contained in:
parent
b0de061e7b
commit
e89241c92f
@ -40,9 +40,15 @@ def self.escape(string)
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_reader :backend
|
||||
delegate :decode, :to => :backend
|
||||
|
||||
def backend
|
||||
@backend || begin
|
||||
self.backend = defined?(::JSON) ? "JSONGem" : "Yaml"
|
||||
@backend
|
||||
end
|
||||
end
|
||||
|
||||
def backend=(name)
|
||||
if name.is_a?(Module)
|
||||
@backend = name
|
||||
@ -77,6 +83,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'
|
||||
|
@ -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
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
module ActiveSupport
|
||||
module JSON
|
||||
unless const_defined?(:ParseError)
|
||||
class ParseError < StandardError
|
||||
end
|
||||
end
|
||||
|
||||
module Backends
|
||||
module Yaml
|
||||
|
@ -36,6 +36,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'
|
||||
|
Loading…
Reference in New Issue
Block a user