class Couchbase::ViewRow
This class encapsulates structured JSON document
@since 1.2.0
It behaves like Hash for document included into row, and has access methods to row data as well.
@see www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-datastore.html
Attributes
The hash built from JSON document.
@since 1.2.0
This is complete response from the Couchbase
@return [Hash]
The document hash.
@since 1.2.0
It usually available when view executed with :include_doc
argument.
@return [Hash]
The identificator of the document
@since 1.2.0
@return [String]
The key which was emitted by map function
@since 1.2.0
@see www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
Usually it is String (the object _id
) but it could be also any compount JSON value.
@return [Object]
The meta data linked to the document
@since 1.2.0
@return [Hash]
The value which was emitted by map function
@since 1.2.0
@see www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-map.html
@return [Object]
Public Class Methods
Initialize the document instance
@since 1.2.0
It takes reference to the bucket, data hash.
@param [Couchbase::Bucket] bucket the reference to connection @param [Hash] data the data hash, which was built from JSON document
representation
# File lib/couchbase/view_row.rb, line 103 def initialize(bucket, data) @bucket = bucket @data = data @key = data.key @value = data.value @id = data.id @last = false case data when ViewRowWithDocs, SpatialViewRowWithDocs @doc = data.document when SpatialViewRowNoDocs, SpatialViewRowWithDocs @geometry = data.geometry @bbox = data.bbox end end
Wraps data hash into ViewRow
instance
@since 1.2.0
@see ViewRow#initialize
@param [Couchbase::Bucket] bucket the reference to connection @param [Hash] data the data hash, which was built from JSON document
representation
@return [ViewRow]
# File lib/couchbase/view_row.rb, line 131 def self.wrap(bucket, data) self.new(bucket, data) end
Public Instance Methods
Get attribute of the document
@since 1.2.0
Fetches attribute from underlying document hash
@param [String] key the attribute name
@return [Object] property value or nil
# File lib/couchbase/view_row.rb, line 144 def [](key) @doc[key] end
Set document attribute
@since 1.2.0
Set or update the attribute in the document hash
@param [String] key the attribute name @param [Object] value the attribute value
@return [Object] the value
# File lib/couchbase/view_row.rb, line 170 def []=(key, value) @doc[key] = value end
Check attribute existence
@since 1.2.0
@param [String] key the attribute name
@return [true, false] true
if the given attribute is present in in
the document.
# File lib/couchbase/view_row.rb, line 156 def has_key?(key) @doc.has_key?(key) end
# File lib/couchbase/view_row.rb, line 183 def inspect desc = "#<#{self.class.name}:#{self.object_id}" [:@id, :@key, :@value, :@doc, :@meta].each do |iv| desc << " #{iv}=#{instance_variable_get(iv).inspect}" end desc << ">" desc end
Signals if this row is last in a stream
@since 1.2.1
@return [true, false] true
if this row is last in a stream
# File lib/couchbase/view_row.rb, line 179 def last? @last end