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
# 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
  ::Marshal.load(data)
rescue TypeError
  data
end

#encode(o) ⇒ Object



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

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