Permalink
Browse files

Automatically prefer Yajl or JSON backend over Yaml, if available

  • Loading branch information...
jeremy committed Feb 5, 2010
1 parent a96bf4a commit 63bb955a99eb46e257655c93dd64e86ebbf05651
View
@@ -1,6 +1,6 @@
*Rails 3.0 (pending)*
* JSON backend for YAJL. #2666 [Brian Lopez]
* JSON backend for YAJL. Preferred if available. #2666 [Brian Lopez]
*Rails 3.0.0 [beta] (February 4, 2010)*
@@ -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 @@ def with_backend(name)
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
@@ -45,7 +45,7 @@ class TestJSONDecoding < ActiveSupport::TestCase
}
# load the default JSON backend
ActiveSupport::JSON.backend
ActiveSupport::JSON.backend = 'Yaml'
backends = %w(Yaml)
backends << "JSONGem" if defined?(::JSON)

4 comments on commit 63bb955

@brianmario

This comment has been minimized.

Show comment
Hide comment
@brianmario

brianmario Feb 5, 2010

Contributor

very nice ;)

Contributor

brianmario replied Feb 5, 2010

very nice ;)

@brianmario

This comment has been minimized.

Show comment
Hide comment
@brianmario

brianmario Feb 5, 2010

Contributor

any chance these would apply cleanly in the 2.3 branch?

Contributor

brianmario replied Feb 5, 2010

any chance these would apply cleanly in the 2.3 branch?

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Feb 5, 2010

Member

probably, yes

Member

jeremy replied Feb 5, 2010

probably, yes

@nono

This comment has been minimized.

Show comment
Hide comment
@nono

nono Mar 1, 2010

Contributor

It should be nice to have the same thing for XmlMini. I wanted to make a patch for it, but I can't run the tests:
*** glibc detected *** /usr/bin/ruby1.8: free(): invalid pointer: 0x00345440 ***

Contributor

nono replied Mar 1, 2010

It should be nice to have the same thing for XmlMini. I wanted to make a patch for it, but I can't run the tests:
*** glibc detected *** /usr/bin/ruby1.8: free(): invalid pointer: 0x00345440 ***

Please sign in to comment.