Class: Couchbase::Document

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/couchbase/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(java_doc) ⇒ Document

Returns a new instance of Document.



9
10
11
12
13
14
15
# File 'lib/couchbase/document.rb', line 9

def initialize(java_doc)
  @id      = java_doc.id
  @cas     = java_doc.cas
  @ttl     = java_doc.expiry
  @content = java_doc.content
  @data    = nil
end

Instance Attribute Details

#casObject (readonly)

Returns the value of attribute cas.



7
8
9
# File 'lib/couchbase/document.rb', line 7

def cas
  @cas
end

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/couchbase/document.rb', line 7

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/couchbase/document.rb', line 7

def id
  @id
end

#ttlObject (readonly)

Returns the value of attribute ttl.



7
8
9
# File 'lib/couchbase/document.rb', line 7

def ttl
  @ttl
end

Instance Method Details

#dataObject Also known as: to_a, to_h, to_hash



21
22
23
24
25
26
27
# File 'lib/couchbase/document.rb', line 21

def data
  @data ||= begin
              MultiJson.load(@content)
            rescue MultiJson::ParseError
              # TODO: figure out what to do here...
            end
end

#to_sObject



17
18
19
# File 'lib/couchbase/document.rb', line 17

def to_s
  @content
end