Skip to content

Commit 285fef5

Browse files
joshkdefunkt
authored andcommitted
instead of using the json gem, or trying to require yajl, lets use multi json which takes care of this for us and includes a vendored json implementation if one is not available
1 parent d1cfe4d commit 285fef5

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

lib/resque.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
require 'redis/namespace'
22

3-
begin
4-
require 'yajl'
5-
rescue LoadError
6-
require 'json'
7-
end
8-
93
require 'resque/version'
104

115
require 'resque/errors'

lib/resque/helpers.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'multi_json'
2+
13
module Resque
24
# Methods used by various classes in Resque.
35
module Helpers
@@ -11,29 +13,17 @@ def redis
1113
# Given a Ruby object, returns a string suitable for storage in a
1214
# queue.
1315
def encode(object)
14-
if defined? Yajl
15-
Yajl::Encoder.encode(object)
16-
else
17-
object.to_json
18-
end
16+
::MultiJson.encode(object)
1917
end
2018

2119
# Given a string, returns a Ruby object.
2220
def decode(object)
2321
return unless object
2422

25-
if defined? Yajl
26-
begin
27-
Yajl::Parser.parse(object, :check_utf8 => false)
28-
rescue Yajl::ParseError => e
29-
raise DecodeException, e
30-
end
31-
else
32-
begin
33-
JSON.parse(object)
34-
rescue JSON::ParserError => e
35-
raise DecodeException, e
36-
end
23+
begin
24+
::MultiJson.decode(object)
25+
rescue ::MultiJson::DecodeError => e
26+
raise DecodeException, e
3727
end
3828
end
3929

resque.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424
s.add_dependency "redis-namespace", "~> 1.0.2"
2525
s.add_dependency "vegas", "~> 0.1.2"
2626
s.add_dependency "sinatra", ">= 0.9.2"
27-
s.add_dependency "json", ">= 1.4.6", "< 1.6"
27+
s.add_dependency "multi_json", "~> 1.0"
2828

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

0 commit comments

Comments
 (0)