Allow to specify json engine used.

Default to MultiJson (with Yajl engine) instead of ActiveSupport::JSON
This commit is contained in:
ccocchi 2012-07-18 23:42:09 +02:00
parent a9143693d4
commit 1db4cae807
5 changed files with 22 additions and 10 deletions

View File

@ -2,5 +2,8 @@ source "http://rubygems.org"
gemspec
# Mocking library
gem 'rspec-mocks'
gem 'yajl-ruby'
group :test do
gem 'rspec-mocks'
end

View File

@ -3,6 +3,7 @@ PATH
specs:
rabl-rails (0.1.0)
activesupport (~> 3.0)
railties (~> 3.0)
GEM
remote: http://rubygems.org/
@ -55,6 +56,7 @@ GEM
sqlite3 (1.3.6)
thor (0.15.4)
tilt (1.3.3)
yajl-ruby (1.1.0)
PLATFORMS
ruby
@ -62,6 +64,6 @@ PLATFORMS
DEPENDENCIES
actionpack (~> 3.0)
rabl-rails!
railties (~> 3.0)
rspec-mocks
sqlite3
yajl-ruby

View File

@ -14,22 +14,29 @@ require 'rabl-rails/library'
require 'rabl-rails/handler'
require 'rabl-rails/railtie'
require 'multi_json'
module RablRails
extend self
mattr_accessor :cache_templates
@@cache_templates = true
mattr_accessor :include_json_root
@@include_json_root = true
def configure
mattr_accessor :json_engine
@@json_engine = :yajl
def self.configure
yield self
post_configure
end
def cache_templates?
def self.cache_templates?
ActionController::Base.perform_caching && @@cache_templates
end
private
def self.post_configure
MultiJson.engine = self.json_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
ActiveSupport::JSON.encode(hash)
MultiJson.encode(hash)
end
end
end

View File

@ -16,8 +16,8 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency "activesupport", "~> 3.0"
s.add_dependency "railties", "~> 3.0"
s.add_development_dependency "sqlite3"
s.add_development_dependency "railties", "~> 3.0"
s.add_development_dependency "actionpack", "~> 3.0"
end