Class: Couchbase::Options::Get

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

Overview

Options for Collection#get

Constant Summary collapse

DEFAULT =

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

Get.new.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#client_context, #parent_span, #retry_strategy, #timeout

Instance Method Summary collapse

Constructor Details

#initialize(projections: [], with_expiry: false, transcoder: JsonTranscoder.new, timeout: nil, retry_strategy: nil, client_context: nil, parent_span: nil) {|self| ... } ⇒ Get

Creates an instance of options for Collection#get

Parameters:

  • projections (Array<String>) (defaults to: [])

    a list of paths that should be loaded if present.

  • with_expiry (Boolean) (defaults to: false)

    if true the expiration will be also fetched with Collection#get

  • transcoder (JsonTranscoder, #decode(String, Integer)) (defaults to: JsonTranscoder.new)

    used for decoding

  • timeout (Integer, #in_milliseconds, nil) (defaults to: nil)

    the time in milliseconds allowed for the operation to complete

  • retry_strategy (Proc, nil) (defaults to: nil)

    the custom retry strategy, if set

  • client_context (Hash, nil) (defaults to: nil)

    the client context data, if set

  • parent_span (Span, nil) (defaults to: nil)

    if set holds the parent span, that should be used for this request

Yield Parameters:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/couchbase/options.rb', line 73

def initialize(projections: [],
               with_expiry: false,
               transcoder: JsonTranscoder.new,
               timeout: nil,
               retry_strategy: nil,
               client_context: nil,
               parent_span: nil)
  super(timeout: timeout, retry_strategy: retry_strategy, client_context: client_context, parent_span: parent_span)
  @projections = projections
  @with_expiry = with_expiry
  @transcoder = transcoder
  @preserve_array_indexes = false
  yield self if block_given?
end

Instance Attribute Details

#preserve_array_indexesBoolean

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 whether to use sparse arrays (default false).

Returns:

  • (Boolean)

    whether to use sparse arrays (default false)



101
102
103
# File 'lib/couchbase/options.rb', line 101

def preserve_array_indexes
  @preserve_array_indexes
end

#projectionsArray<String>

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 list of paths to project.

Returns:

  • (Array<String>)

    list of paths to project



105
106
107
# File 'lib/couchbase/options.rb', line 105

def projections
  @projections
end

#transcoderJsonTranscoder, #decode(String, Integer)

Returns:



59
60
61
# File 'lib/couchbase/options.rb', line 59

def transcoder
  @transcoder
end

#with_expiryBoolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/couchbase/options.rb', line 58

def with_expiry
  @with_expiry
end

Instance Method Details

#need_projected_get?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:

  • (Boolean)


109
110
111
# File 'lib/couchbase/options.rb', line 109

def need_projected_get?
  @with_expiry || !@projections&.empty?
end

#project(*paths) ⇒ Object

Allows to specify a custom list paths to fetch from the document instead of the whole.

Note that a maximum of 16 individual paths can be projected at a time due to a server limitation. If you need more than that, think about fetching less-generic paths or the full document straight away.

Parameters:

  • paths (String, Array<String>)

    a path that should be loaded if present.



94
95
96
97
# File 'lib/couchbase/options.rb', line 94

def project(*paths)
  @projections ||= []
  @projections |= paths.flatten # union with current projections
end

#to_backendObject

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.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/couchbase/options.rb', line 114

def to_backend
  options = {
    timeout: Utils::Time.extract_duration(@timeout),
  }
  options.update(with_expiry: true) if @with_expiry
  unless @projections&.empty?
    options.update({
      projections: @projections,
      preserve_array_indexes: @preserve_array_indexes,
    })
  end
  options
end