Class: Resque::MultiJsonCoder

Inherits:
Coder
  • Object
show all
Defined in:
lib/resque/multi_json_coder.rb

Instance Method Summary collapse

Methods inherited from Coder

#dump, #load

Instance Method Details

#decode(object) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/resque/multi_json_coder.rb', line 23

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

#encode(object) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/resque/multi_json_coder.rb', line 15

def encode(object)
  if MultiJson.respond_to?(:dump) && MultiJson.respond_to?(:load)
    MultiJson.dump object
  else
    MultiJson.encode object
  end
end