Class: Couchbase::ViewRow
- Inherits:
-
Object
- Object
- Couchbase::ViewRow
- Includes:
- Constants
- Defined in:
- lib/couchbase/view_row.rb
Overview
This class encapsulates structured JSON document
It behaves like Hash for document included into row, and has access methods to row data as well.
Direct Known Subclasses
Constant Summary
Constants included from Constants
Constants::S_CAS, Constants::S_DOC, Constants::S_FLAGS, Constants::S_ID, Constants::S_IS_LAST, Constants::S_KEY, Constants::S_META, Constants::S_VALUE
Instance Attribute Summary collapse
-
#data ⇒ Hash
The hash built from JSON document.
-
#doc ⇒ Hash
The document hash.
-
#id ⇒ String
The identificator of the document.
-
#key ⇒ Object
The key which was emitted by map function.
-
#meta ⇒ Hash
The meta data linked to the document.
-
#value ⇒ Object
The value which was emitted by map function.
Class Method Summary collapse
-
.wrap(bucket, data) ⇒ ViewRow
Wraps data hash into ViewRow instance.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get attribute of the document.
-
#[]=(key, value) ⇒ Object
Set document attribute.
-
#has_key?(key) ⇒ true, false
Check attribute existence.
-
#initialize(bucket, data) ⇒ ViewRow
constructor
Initialize the document instance.
- #inspect ⇒ Object
-
#last? ⇒ true, false
Signals if this row is last in a stream.
Constructor Details
#initialize(bucket, data) ⇒ ViewRow
Initialize the document instance
It takes reference to the bucket, data hash.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/couchbase/view_row.rb', line 124 def initialize(bucket, data) @bucket = bucket @data = data @key = data.key @last = false @id = data.id unless data.is_a?(ViewRowReduced) case data when ViewRowWithDocs, SpatialViewRowWithDocs @doc = data.document when ViewRowReduced @value = MultiJson.load(data.value) when SpatialViewRowNoDocs, SpatialViewRowWithDocs @geometry = data.geometry @bbox = data.bbox end end |
Instance Attribute Details
#data ⇒ Hash
The hash built from JSON document.
This is complete response from the Couchbase
69 70 71 |
# File 'lib/couchbase/view_row.rb', line 69 def data @data end |
#doc ⇒ Hash
The document hash.
It usually available when view executed with :include_doc argument.
99 100 101 |
# File 'lib/couchbase/view_row.rb', line 99 def doc @doc end |
#id ⇒ String
The identificator of the document
106 107 108 |
# File 'lib/couchbase/view_row.rb', line 106 def id @id end |
#key ⇒ Object
The key which was emitted by map function
Usually it is String (the object _id) but it could be also any compount JSON value.
81 82 83 |
# File 'lib/couchbase/view_row.rb', line 81 def key @key end |
#meta ⇒ Hash
The meta data linked to the document
113 114 115 |
# File 'lib/couchbase/view_row.rb', line 113 def @meta end |
#value ⇒ Object
The value which was emitted by map function
90 91 92 |
# File 'lib/couchbase/view_row.rb', line 90 def value @value end |
Class Method Details
.wrap(bucket, data) ⇒ ViewRow
Wraps data hash into ViewRow instance
153 154 155 |
# File 'lib/couchbase/view_row.rb', line 153 def self.wrap(bucket, data) self.new(bucket, data) end |
Instance Method Details
#[](key) ⇒ Object
Get attribute of the document
Fetches attribute from underlying document hash
166 167 168 |
# File 'lib/couchbase/view_row.rb', line 166 def [](key) @doc[key] end |
#[]=(key, value) ⇒ Object
Set document attribute
Set or update the attribute in the document hash
192 193 194 |
# File 'lib/couchbase/view_row.rb', line 192 def []=(key, value) @doc[key] = value end |
#has_key?(key) ⇒ true, false
Check attribute existence
178 179 180 |
# File 'lib/couchbase/view_row.rb', line 178 def has_key?(key) @doc.has_key?(key) end |
#inspect ⇒ Object
205 206 207 208 209 210 211 212 |
# File 'lib/couchbase/view_row.rb', line 205 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 |
#last? ⇒ true, false
Signals if this row is last in a stream
201 202 203 |
# File 'lib/couchbase/view_row.rb', line 201 def last? @last end |