Skip to content
Browse files

Use newer MultiJson syntax if available

  • Loading branch information...
1 parent 5d7d26f commit bfceaa00affc4bdbdb085add36f61e316ee4003c @arsduo committed Apr 16, 2012
Showing with 5 additions and 4 deletions.
  1. +4 −3 lib/resque/multi_json_coder.rb
  2. +1 −1 test/multi_queue_test.rb
View
7 lib/resque/multi_json_coder.rb
@@ -3,21 +3,22 @@
# OkJson won't work because it doesn't serialize symbols
# in the same way yajl and json do.
-if MultiJson.engine.to_s == 'MultiJson::Engines::OkJson'
+engine = MultiJson.respond_to?(:adapter) ? MultiJson.adapter : MultiJson.engine
+if engine.to_s == 'MultiJson::Engines::OkJson'
@ereslibre
ereslibre added a note Apr 17, 2012

I guess you also need to param this. In the new version it will be MultiJson::Adapters::OkJson instead of MultiJson::Engines::OkJson

@arsduo
Owner
arsduo added a note Apr 17, 2012

Good point, thanks. I'll update that today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
raise "Please install the yajl-ruby or json gem"
end
module Resque
class MultiJsonCoder < Coder
def encode(object)
- ::MultiJson.encode(object)
+ ::MultiJson.respond_to?(:dump) ? ::MultiJson.dump(object) : ::MultiJson.encode(object)
end
def decode(object)
return unless object
begin
- ::MultiJson.decode(object)
+ ::MultiJson.respond_to?(:load) ? ::MultiJson.load(object) : ::MultiJson.decode(object)
rescue ::MultiJson::DecodeError => e
raise DecodeException, e.message, e.backtrace
end
View
2 test/multi_queue_test.rb
@@ -1,6 +1,6 @@
require "test_helper"
-describe "Resque::MulitQueue" do
+describe "Resque::MultiQueue" do
let(:redis) { Resque.redis }
let(:coder) { Resque::MultiJsonCoder.new }

0 comments on commit bfceaa0

Please sign in to comment.
Something went wrong with that request. Please try again.