Skip to content

Commit 55daf0d

Browse files
committed
Remove MultiJSON.
By now, rubinius and jruby have good versions of JSON.
1 parent f793235 commit 55daf0d

File tree

7 files changed

+34
-49
lines changed

7 files changed

+34
-49
lines changed

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ end
1414

1515
group :test do
1616
gem "rack-test", "~> 0.5"
17-
gem "yajl-ruby", :platforms => :mri
18-
gem "json", "~>1.5.3", :platforms => [:jruby, :rbx]
17+
gem "json"
1918
gem "i18n"
2019
gem "minitest"
2120
end

lib/resque.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
require 'resque/queue'
1616
require 'resque/multi_queue'
1717
require 'resque/coder'
18-
require 'resque/multi_json_coder'
18+
require 'resque/json_coder'
1919

2020
require 'resque/vendor/utf8_util'
2121

@@ -55,9 +55,9 @@ def redis=(server)
5555
end
5656

5757
# Encapsulation of encode/decode. Overwrite this to use it across Resque.
58-
# This defaults to MultiJson for backwards compatibilty.
58+
# This defaults to JSON for backwards compatibilty.
5959
def coder
60-
@coder ||= MultiJsonCoder.new
60+
@coder ||= JsonCoder.new
6161
end
6262
attr_writer :coder
6363

lib/resque/json_coder.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'resque/coder'
2+
require 'json'
3+
4+
module Resque
5+
class JsonCoder < Coder
6+
def encode(object)
7+
if JSON.respond_to?(:dump) && JSON.respond_to?(:load)
8+
JSON.dump object
9+
else
10+
JSON.encode object
11+
end
12+
end
13+
14+
def decode(object)
15+
return unless object
16+
17+
begin
18+
if JSON.respond_to?(:dump) && JSON.respond_to?(:load)
19+
JSON.load object
20+
else
21+
JSON.decode object
22+
end
23+
rescue JSON::ParserError => e
24+
raise DecodeException, e.message, e.backtrace
25+
end
26+
end
27+
end
28+
end

lib/resque/multi_json_coder.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

resque.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
2020
s.add_dependency "redis-namespace", "~> 1.0"
2121
s.add_dependency "vegas", "~> 0.1.2"
2222
s.add_dependency "sinatra", ">= 0.9.2"
23-
s.add_dependency "multi_json", "~> 1.0"
23+
s.add_dependency "json"
2424

2525
s.description = <<description
2626
Resque is a Redis-backed Ruby library for creating background jobs,

test/multi_queue_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe "Resque::MultiQueue" do
44
let(:redis) { Resque.redis }
5-
let(:coder) { Resque::MultiJsonCoder.new }
5+
let(:coder) { Resque::JsonCoder.new }
66

77
before do
88
redis.flushall

test/resque_failure_redis_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ class GeneratorError
1919
end
2020

2121
it 'cleans up bad strings before saving the failure, in order to prevent errors on the resque UI' do
22-
# test assumption: the bad string should not be able to round trip though JSON
23-
assert_raises(MultiJson::DecodeError, JSON::GeneratorError) {
24-
MultiJson.decode(MultiJson.encode(@bad_string))
25-
}
26-
2722
@redis_backend.save
2823
Resque::Failure::Redis.all # should not raise an error
2924
end

0 commit comments

Comments
 (0)