Class: Tarantool16::Connection::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/tarantool16/connection/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sync, err, data) ⇒ Option

Returns a new instance of Option.



8
9
10
11
12
# File 'lib/tarantool16/connection/response.rb', line 8

def initialize(sync, err, data)
  @sync = sync
  @error = err
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/tarantool16/connection/response.rb', line 7

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/tarantool16/connection/response.rb', line 7

def error
  @error
end

#syncObject (readonly)

Returns the value of attribute sync.



7
8
9
# File 'lib/tarantool16/connection/response.rb', line 7

def sync
  @sync
end

Class Method Details

.error(sync, err, message = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/tarantool16/connection/response.rb', line 30

def self.error(sync, err, message = nil)
  if err.is_a? Class
    err = err.new message
  end
  new(sync, err, nil)
end

.ok(sync, code, data) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/tarantool16/connection/response.rb', line 22

def self.ok(sync, code, data)
  if code == 0
    new(sync, nil, data)
  else
    new(sync, ::Tarantool16::DBError.with_code_message(code&(REQUEST_TYPE_ERROR-1), data), nil)
  end
end

Instance Method Details

#inspectObject



37
38
39
40
41
42
43
44
# File 'lib/tarantool16/connection/response.rb', line 37

def inspect
  s = @sync ? " sync=#{sync}" : ""
  if ok?
    "<Option#{s} data=#{@data.inspect}>"
  else
    "<Option#{s} error=#{@error.inspect}>"
  end
end

#ok?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/tarantool16/connection/response.rb', line 14

def ok?
  !@error
end

#raise_if_error!Object

Raises:



18
19
20
# File 'lib/tarantool16/connection/response.rb', line 18

def raise_if_error!
  raise @error if @error
end