Class: Libcouchbase::SubdocRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/libcouchbase/subdoc_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, quiet, bucket: nil, exec_opts: nil) ⇒ SubdocRequest

Returns a new instance of SubdocRequest.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/libcouchbase/subdoc_request.rb', line 6

def initialize(key, quiet, bucket: nil, exec_opts: nil)
    @key = key.to_s
    raise ArgumentError.new("invalid document key #{key.inspect}") unless @key.length > 0
    @refs = []
    @mode = nil
    @quiet = quiet
    @specs = []
    @ignore = []

    @bucket = bucket
    @exec_opts = exec_opts
end

Instance Attribute Details

#ignoreObject (readonly)

Returns the value of attribute ignore.



19
20
21
# File 'lib/libcouchbase/subdoc_request.rb', line 19

def ignore
  @ignore
end

#keyObject (readonly)

Returns the value of attribute key.



19
20
21
# File 'lib/libcouchbase/subdoc_request.rb', line 19

def key
  @key
end

#modeObject (readonly)

Returns the value of attribute mode.



19
20
21
# File 'lib/libcouchbase/subdoc_request.rb', line 19

def mode
  @mode
end

Instance Method Details

#execute!(**opts) ⇒ Object

When not used in block form



41
42
43
44
45
46
47
# File 'lib/libcouchbase/subdoc_request.rb', line 41

def execute!(**opts)
    opts = @exec_opts.merge(opts)
    @exec_opts = nil
    bucket = @bucket
    @bucket = nil
    bucket.subdoc_execute!(self, **opts)
end

#free_memoryObject

Internal use only



35
36
37
38
# File 'lib/libcouchbase/subdoc_request.rb', line 35

def free_memory
    @refs = nil
    @mem = nil
end

#remove(path, quiet: nil, **opts) ⇒ Object

Mutations


69
70
71
72
73
# File 'lib/libcouchbase/subdoc_request.rb', line 69

def remove(path, quiet: nil, **opts)
    quiet = @quiet if quiet.nil?
    new_spec(quiet, path, :sdcmd_remove, :mutate)
    self
end

#to_specs_arrayObject

Internal use only



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/libcouchbase/subdoc_request.rb', line 22

def to_specs_array
    return @mem if @mem # effectively freezes this object
    number = @specs.length
    @mem = FFI::MemoryPointer.new(::Libcouchbase::Ext::SDSPEC, number, false)
    @specs.each_with_index do |spec, index|
        struct_bytes = spec.to_ptr.get_bytes(0, ::Libcouchbase::Ext::SDSPEC.size) # (offset, length)
        @mem[index].put_bytes(0, struct_bytes) # (offset, byte_string)
    end
    @specs = nil
    [@mem, number]
end