Let MultiJson select default JSON adapter (engine), support for latest MultiJson syntax

This commit is contained in:
Alex Smelik 2012-09-12 10:45:45 -07:00
parent 7e6da1a619
commit 28f3dbedd0
2 changed files with 3 additions and 4 deletions

View File

@ -27,7 +27,6 @@ module RablRails
@@include_json_root = true
mattr_reader :json_engine
@@json_engine = :yajl
mattr_accessor :use_custom_responder
@@use_custom_responder = false
@ -42,7 +41,7 @@ module RablRails
end
def self.json_engine=(name)
MultiJson.engine = name
MultiJson.respond_to?(:use) ? MultiJson.use(name) : MultiJson.engine = name
@@json_engine = name
rescue LoadError
Rails.logger.warn %Q(WARNING: rabl-rails could not load "#{self.json_engine}" as JSON engine, fallback to default)
@ -53,6 +52,6 @@ module RablRails
end
def self.load_default_engines!
self.json_engine = :yajl
self.json_engine = MultiJson.respond_to?(default_adapter) ? MultiJson.default_adapter : MultiJson.default_engine
end
end

View File

@ -3,7 +3,7 @@ module RablRails
class JSON < Base
def format_output(hash)
hash = { _options[:root_name] => hash } if _options[:root_name] && RablRails.include_json_root
MultiJson.encode(hash)
MultiJson.respond_to?(:dump) ? MultiJson.dump(hash) : MultiJson.encode(hash)
end
end
end