Class: Couchbase::Collection::LookupInResult

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

Direct Known Subclasses

LookupInReplicaResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|self| ... } ⇒ LookupInResult

Returns a new instance of LookupInResult.

Yield Parameters:



204
205
206
207
# File 'lib/couchbase/collection_options.rb', line 204

def initialize
  @deleted = false
  yield self if block_given?
end

Instance Attribute Details

#casInteger

Returns holds the CAS value of the fetched document.

Returns:

  • (Integer)

    holds the CAS value of the fetched document



163
164
165
# File 'lib/couchbase/collection_options.rb', line 163

def cas
  @cas
end

#deletedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



222
223
224
# File 'lib/couchbase/collection_options.rb', line 222

def deleted
  @deleted
end

#encodedArray<SubDocumentField>

Returns holds the encoded subdocument responses.

Returns:



201
202
203
# File 'lib/couchbase/collection_options.rb', line 201

def encoded
  @encoded
end

#transcoderJsonTranscoder

Returns The default transcoder which should be used.

Returns:



210
211
212
# File 'lib/couchbase/collection_options.rb', line 210

def transcoder
  @transcoder
end

Instance Method Details

#content(path_or_index, transcoder = self.transcoder) ⇒ Object

Decodes the content at the given index (or path)

Parameters:

  • path_or_index (Integer, String)

    the index (or path) of the subdocument value to decode

Returns:

  • (Object)

    the decoded



170
171
172
173
174
175
176
# File 'lib/couchbase/collection_options.rb', line 170

def content(path_or_index, transcoder = self.transcoder)
  field = get_field_at_index(path_or_index)

  raise field.error unless field.error.nil?

  transcoder.decode(field.value, :json)
end

#deleted?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns true if the document is a tombstone (created in deleted state).

Returns:

  • (Boolean)

    true if the document is a tombstone (created in deleted state)

See Also:



217
218
219
# File 'lib/couchbase/collection_options.rb', line 217

def deleted?
  @deleted
end

#exists?(path_or_index) ⇒ Boolean

Allows to check if a value at the given index exists

Parameters:

  • path_or_index (Integer, String)

    the index (or path) of the subdocument value to check

Returns:

  • (Boolean)

    true if a value is present at the index, false otherwise



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/couchbase/collection_options.rb', line 183

def exists?(path_or_index)
  field =
    case path_or_index
    when String
      encoded.find { |f| f.path == path_or_index }
    else
      return false unless path_or_index >= 0 && path_or_index < encoded.size

      encoded[path_or_index]
    end
  return false unless field

  raise field.error unless field.error.nil? || field.error.is_a?(Error::PathNotFound)

  field.exists
end