Class: Couchbase::Transcoder::Document

Inherits:
Base
  • Object
show all
Defined in:
lib/couchbase/transcoder.rb

Instance Method Summary collapse

Instance Method Details

#decode(d) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/couchbase/transcoder.rb', line 29

def decode(d)
  decoded = super
  data = if decoded.respond_to?(:to_str)
           decoded
         else
           decoded.getData.to_s
         end

  MultiJson.load(data)
rescue MultiJson::LoadError
  begin
    ::Marshal.load(data)
  rescue TypeError
    data
  end
end

#encode(o) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/couchbase/transcoder.rb', line 46

def encode(o)
  super MultiJson.dump(o)
rescue ArgumentError => e
  ex = Couchbase::Error::ValueFormat.new
  ex.inner_exception = e
  fail ex
end