Class: Couchbase::MutateInSpec

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

Constant Summary collapse

CAS =
"${Mutation.CAS}"
SEQ_NO =
"${Mutation.seqno}"
VALUE_CRC32C =
"${Mutation.value_crc32c}"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramObject (readonly)

Returns the value of attribute param.


251
252
253
# File 'lib/couchbase/subdoc.rb', line 251

def param
  @param
end

#pathObject (readonly)

Returns the value of attribute path.


250
251
252
# File 'lib/couchbase/subdoc.rb', line 250

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.


249
250
251
# File 'lib/couchbase/subdoc.rb', line 249

def type
  @type
end

Class Method Details

.array_add_unique(path, value) ⇒ MutateInSpec

Creates a command with the intent of inserting a value into an existing JSON array, but only if the value is not already contained in the array (by way of string comparison).

Will error if the last element of the path does not exist or is not an array.

Parameters:

  • path (String)

    the path identifying an array to which to append the value, and an index. E.g. “foo.bar

  • value (Object, Symbol)

    the value to insert.

Returns:

[View source]

195
196
197
# File 'lib/couchbase/subdoc.rb', line 195

def self.array_add_unique(path, value)
  new(:array_add_unique, path, value)
end

.array_append(path, values) ⇒ MutateInSpec

Creates a command with the intention of appending a value to an existing JSON array.

Will error if the last element of the path does not exist or is not an array.

Parameters:

  • path (String)

    the path identifying an array to which to append the value.

  • values (Array)

    the value(s) to append.

Returns:

[View source]

158
159
160
# File 'lib/couchbase/subdoc.rb', line 158

def self.array_append(path, values)
  new(:array_push_last, path, values)
end

.array_insert(path, values) ⇒ MutateInSpec

Creates a command with the intention of inserting a value into an existing JSON array.

Will error if the last element of the path does not exist or is not an array.

Parameters:

  • path (String)

    the path identifying an array to which to append the value, and an index. E.g. “foo.bar

  • values (Array)

    the value(s) to insert.

Returns:

[View source]

182
183
184
# File 'lib/couchbase/subdoc.rb', line 182

def self.array_insert(path, values)
  new(:array_insert, path, values)
end

.array_prepend(path, values) ⇒ MutateInSpec

Creates a command with the intention of prepending a value to an existing JSON array.

Will error if the last element of the path does not exist or is not an array.

Parameters:

  • path (String)

    the path identifying an array to which to append the value.

  • values (Array)

    the value(s) to prepend.

Returns:

[View source]

170
171
172
# File 'lib/couchbase/subdoc.rb', line 170

def self.array_prepend(path, values)
  new(:array_push_first, path, values)
end

.decrement(path, delta) ⇒ MutateInSpec

Creates a command with the intent of decrementing a numerical field in a JSON object.

If the field does not exist, then it is created and takes the value of delta * -1

Parameters:

  • path (String)

    the path identifying a numerical field to adjust or create

  • delta (Integer)

    the value to decrement the field by

Returns:

[View source]

219
220
221
# File 'lib/couchbase/subdoc.rb', line 219

def self.decrement(path, delta)
  new(:counter, path, -1 * delta.abs)
end

.increment(path, delta) ⇒ MutateInSpec

Creates a command with the intent of incrementing a numerical field in a JSON object.

If the field does not exist, then it is created and takes the value of delta

Parameters:

  • path (String)

    the path identifying a numerical field to adjust or create

  • delta (Integer)

    the value to increment the field by

Returns:

[View source]

207
208
209
# File 'lib/couchbase/subdoc.rb', line 207

def self.increment(path, delta)
  new(:counter, path, delta.abs)
end

.insert(path, value) ⇒ MutateInSpec

Creates a command with the intention of inserting a new value in a JSON object.

Will error if the last element of the path already exists.

Parameters:

  • path (String)

    the path identifying where to insert the value.

  • value (Object, Symbol)

    the value to insert. When symbol specified and it is matches to known macro, it will be expanded

Returns:

[View source]

122
123
124
# File 'lib/couchbase/subdoc.rb', line 122

def self.insert(path, value)
  new(:dict_add, path, value)
end

.remove(path) ⇒ MutateInSpec

Creates a command with the intention of removing an existing value in a JSON object.

Will error if the path does not exist.

Parameters:

  • path

    the path identifying what to remove.

Returns:

[View source]

133
134
135
# File 'lib/couchbase/subdoc.rb', line 133

def self.remove(path)
  new(:remove, path, nil)
end

.replace(path, value) ⇒ MutateInSpec

Creates a command with the intention of replacing an existing value in a JSON document.

If the path is empty (“”), then the value will be used for the document's full body. Will error if the last element of the path does not exist.

Parameters:

  • path (String)

    the path identifying where to replace the value.

  • value (Object, Symbol)

    the value to replace with. When symbol specified and it is matches to known macro, it will be expanded

Returns:

[View source]

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

def self.replace(path, value)
  new(path.empty? ? :set_doc : :replace, path, value)
end

.upsert(path, value) ⇒ MutateInSpec

Creates a command with the intention of upserting a value in a JSON object.

That is, the value will be replaced if the path already exists, or inserted if not.

Parameters:

  • path (String)

    the path identifying where to upsert the value.

  • value (Object, Symbol)

    the value to upsert. When symbol specified and it is matches to known macro, it will be expanded

Returns:

[View source]

146
147
148
# File 'lib/couchbase/subdoc.rb', line 146

def self.upsert(path, value)
  new(:dict_upsert, path, value)
end

Instance Method Details

#create_pathObject

[View source]

228
229
230
231
# File 'lib/couchbase/subdoc.rb', line 228

def create_path
  @create_path = true
  self
end

#create_path?Boolean

Returns:

  • (Boolean)
[View source]

237
238
239
# File 'lib/couchbase/subdoc.rb', line 237

def create_path?
  @create_path
end

#expand_macros?Boolean

Returns:

  • (Boolean)
[View source]

241
242
243
# File 'lib/couchbase/subdoc.rb', line 241

def expand_macros?
  @expand_macros
end

#xattrObject

[View source]

223
224
225
226
# File 'lib/couchbase/subdoc.rb', line 223

def xattr
  @xattr = true
  self
end

#xattr?Boolean

Returns:

  • (Boolean)
[View source]

233
234
235
# File 'lib/couchbase/subdoc.rb', line 233

def xattr?
  @xattr
end