Permalink
Browse files

Remove MultiJSON.

By now, rubinius and jruby have good versions of JSON.
  • Loading branch information...
1 parent f793235 commit 55daf0dadcbe2ce74b77608919bf388d817d0692 @steveklabnik steveklabnik committed Sep 25, 2012
Showing with 34 additions and 49 deletions.
  1. +1 −2 Gemfile
  2. +3 −3 lib/resque.rb
  3. +28 −0 lib/resque/json_coder.rb
  4. +0 −37 lib/resque/multi_json_coder.rb
  5. +1 −1 resque.gemspec
  6. +1 −1 test/multi_queue_test.rb
  7. +0 −5 test/resque_failure_redis_test.rb
View
@@ -14,8 +14,7 @@ end
group :test do
gem "rack-test", "~> 0.5"
- gem "yajl-ruby", :platforms => :mri
- gem "json", "~>1.5.3", :platforms => [:jruby, :rbx]
+ gem "json"
gem "i18n"
gem "minitest"
end
View
@@ -15,7 +15,7 @@
require 'resque/queue'
require 'resque/multi_queue'
require 'resque/coder'
-require 'resque/multi_json_coder'
+require 'resque/json_coder'
require 'resque/vendor/utf8_util'
@@ -55,9 +55,9 @@ def redis=(server)
end
# Encapsulation of encode/decode. Overwrite this to use it across Resque.
- # This defaults to MultiJson for backwards compatibilty.
+ # This defaults to JSON for backwards compatibilty.
def coder
- @coder ||= MultiJsonCoder.new
+ @coder ||= JsonCoder.new
end
attr_writer :coder
View
@@ -0,0 +1,28 @@
+require 'resque/coder'
+require 'json'
+
+module Resque
+ class JsonCoder < Coder
+ def encode(object)
+ if JSON.respond_to?(:dump) && JSON.respond_to?(:load)
+ JSON.dump object
+ else
+ JSON.encode object
+ end
+ end
+
+ def decode(object)
+ return unless object
+
+ begin
+ if JSON.respond_to?(:dump) && JSON.respond_to?(:load)
+ JSON.load object
+ else
+ JSON.decode object
+ end
+ rescue JSON::ParserError => e
+ raise DecodeException, e.message, e.backtrace
+ end
+ end
+ end
+end
@@ -1,37 +0,0 @@
-require 'multi_json'
-require 'resque/coder'
-
-# OkJson won't work because it doesn't serialize symbols
-# in the same way yajl and json do.
-
-if MultiJson.respond_to?(:adapter)
- raise "Please install the yajl-ruby or json gem" if MultiJson.adapter.to_s == 'MultiJson::Adapters::OkJson'
-elsif MultiJson.respond_to?(:engine)
- raise "Please install the yajl-ruby or json gem" if MultiJson.engine.to_s == 'MultiJson::Engines::OkJson'
-end
-
-module Resque
- class MultiJsonCoder < Coder
- def encode(object)
- if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load)
- MultiJson.dump object
- else
- MultiJson.encode object
- end
- end
-
- def decode(object)
- return unless object
-
- begin
- if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load)
- MultiJson.load object
- else
- MultiJson.decode object
- end
- rescue ::MultiJson::DecodeError => e
- raise DecodeException, e.message, e.backtrace
- end
- end
- end
-end
View
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency "redis-namespace", "~> 1.0"
s.add_dependency "vegas", "~> 0.1.2"
s.add_dependency "sinatra", ">= 0.9.2"
- s.add_dependency "multi_json", "~> 1.0"
+ s.add_dependency "json"
s.description = <<description
Resque is a Redis-backed Ruby library for creating background jobs,
View
@@ -2,7 +2,7 @@
describe "Resque::MultiQueue" do
let(:redis) { Resque.redis }
- let(:coder) { Resque::MultiJsonCoder.new }
+ let(:coder) { Resque::JsonCoder.new }
before do
redis.flushall
@@ -19,11 +19,6 @@ class GeneratorError
end
it 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
- # test assumption: the bad string should not be able to round trip though JSON
- assert_raises(MultiJson::DecodeError, JSON::GeneratorError) {
- MultiJson.decode(MultiJson.encode(@bad_string))
- }
-
@redis_backend.save
Resque::Failure::Redis.all # should not raise an error
end

0 comments on commit 55daf0d

Please sign in to comment.