Class: Mongo::Crypt::Status Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/crypt/status.rb

Overview

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

A wrapper around mongocrypt_status_t, representing the status of a mongocrypt_t handle.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer: nil) ⇒ Status

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.

Note:

When initializing a Status object with a pointer, it is

Create a new Status object

recommended that you use the #self.from_pointer method



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mongo/crypt/status.rb', line 32

def initialize(pointer: nil)
  # If a pointer is passed in, this class is not responsible for
  # destroying that pointer and deallocating data.
  #
  # FFI::AutoPointer uses a custom release strategy to automatically free
  # the pointer once this object goes out of scope
  @status = pointer || FFI::AutoPointer.new(
                        Binding.mongocrypt_status_new,
                        Binding.method(:mongocrypt_status_destroy)
                      )
end

Class Method Details

.from_pointer(pointer) ⇒ Mongo::Crypt::Status

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.

Initialize a Status object from an existing pointer to a mongocrypt_status_t object.



51
52
53
# File 'lib/mongo/crypt/status.rb', line 51

def self.from_pointer(pointer)
  self.new(pointer: pointer)
end

Instance Method Details

#codeInteger

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.

Return the integer code associated with the status



87
88
89
# File 'lib/mongo/crypt/status.rb', line 87

def code
  Binding.mongocrypt_status_code(@status)
end

#labelSymbol

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.

Return the label of the status



80
81
82
# File 'lib/mongo/crypt/status.rb', line 80

def label
  Binding.mongocrypt_status_type(@status)
end

#messageString

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.

Return the status message



94
95
96
97
# File 'lib/mongo/crypt/status.rb', line 94

def message
  message = Binding.mongocrypt_status_message(@status, nil)
  message || ''
end

#ok?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.

Checks whether the status is labeled :ok



102
103
104
# File 'lib/mongo/crypt/status.rb', line 102

def ok?
  Binding.mongocrypt_status_ok(@status)
end

#raise_crypt_errorObject

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.

Raises a Mongo::Error:CryptError corresponding to the information stored in this status

Does nothing if self.ok? is true



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mongo/crypt/status.rb', line 118

def raise_crypt_error
  return if ok?

  if label == :error_kms
    error = Error::KmsError.new(message, code: code)
  else
    error = Error::CryptError.new(message, code: code)
  end

  raise error
end

#refFFI::Pointer

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 the reference to the underlying mongocrypt_status_t object



110
111
112
# File 'lib/mongo/crypt/status.rb', line 110

def ref
  @status
end

#update(label, code, message) ⇒ Mongo::Crypt::Status

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.

Set a label, code, and message on the Status



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/mongo/crypt/status.rb', line 62

def update(label, code, message)
  unless [:ok, :error_client, :error_kms].include?(label)
    raise ArgumentError.new(
      "#{label} is an invalid value for a Mongo::Crypt::Status label. " +
      "Label must have one of the following values: :ok, :error_client, :error_kms"
    )
  end

  message_length = message ? message.bytesize + 1 : 0
  Binding.mongocrypt_status_set(@status, label, code, message, message_length)

  self
end