Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
instead of using the json gem, or trying to require yajl, lets use mu…
…lti json which takes care of this for us and includes a vendored json implementation if one is not available
  • Loading branch information
joshk authored and defunkt committed Jun 25, 2011
1 parent d1cfe4d commit 285fef5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
6 changes: 0 additions & 6 deletions lib/resque.rb
@@ -1,11 +1,5 @@
require 'redis/namespace'

begin
require 'yajl'
rescue LoadError
require 'json'
end

require 'resque/version'

require 'resque/errors'
Expand Down
24 changes: 7 additions & 17 deletions lib/resque/helpers.rb
@@ -1,3 +1,5 @@
require 'multi_json'

module Resque
# Methods used by various classes in Resque.
module Helpers
Expand All @@ -11,29 +13,17 @@ def redis
# Given a Ruby object, returns a string suitable for storage in a
# queue.
def encode(object)
if defined? Yajl
Yajl::Encoder.encode(object)
else
object.to_json
end
::MultiJson.encode(object)
end

# Given a string, returns a Ruby object.
def decode(object)
return unless object

if defined? Yajl
begin
Yajl::Parser.parse(object, :check_utf8 => false)
rescue Yajl::ParseError => e
raise DecodeException, e
end
else
begin
JSON.parse(object)
rescue JSON::ParserError => e
raise DecodeException, e
end
begin
::MultiJson.decode(object)
rescue ::MultiJson::DecodeError => e
raise DecodeException, e
end
end

Expand Down
2 changes: 1 addition & 1 deletion resque.gemspec
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency "redis-namespace", "~> 1.0.2"
s.add_dependency "vegas", "~> 0.1.2"
s.add_dependency "sinatra", ">= 0.9.2"
s.add_dependency "json", ">= 1.4.6", "< 1.6"
s.add_dependency "multi_json", "~> 1.0"

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

0 comments on commit 285fef5

Please sign in to comment.