Revert to old MultiJson syntax.

This commit is contained in:
Alex Smelik 2012-09-13 08:05:52 -07:00
parent 28f3dbedd0
commit 360d70b838
3 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,10 @@
# CHANGELOG # CHANGELOG
## 0.1.4 (Unreleased)
* Use MultiJson's preferred JSON engine as default
## 0.1.3 ## 0.1.3
* Render correcly when variables are not passed via the assigns ivar but as helper methods * Render correctly when variables are not passed via the assigns ivar but as helper methods
(decent_exposure, focused_controller) (decent_exposure, focused_controller)
* Add custom Responder * Add custom Responder
@ -13,7 +16,7 @@
## 0.1.1 ## 0.1.1
* Add CHANGELOG * Add CHANGELOG
* Remove unnused test in loop * Remove unused test in loop
* Speed up rendering by not double copying variable from context * Speed up rendering by not double copying variable from context
* Rename private variable to avoid name conflict * Rename private variable to avoid name conflict
* Remove sqlite3 development dependency * Remove sqlite3 development dependency

View File

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

View File

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