Class: Mongoid::Fields::Encrypted

Inherits:
Standard
  • Object
show all
Defined in:
lib/mongoid/fields/encrypted.rb

Overview

Represents a field that should be encrypted.

Instance Attribute Summary

Attributes inherited from Standard

#default_val, #label, #name, #options

Instance Method Summary collapse

Methods inherited from Standard

#add_atomic_changes, #association, #eval_default, #foreign_key?, #lazy?, #localize_present?, #localized?, #object_id_field?, #pre_processed?, #type

Constructor Details

#initialize(name, options = {}) ⇒ Encrypted

Returns a new instance of Encrypted.



8
9
10
11
12
13
14
15
# File 'lib/mongoid/fields/encrypted.rb', line 8

def initialize(name, options = {})
  @encryption_options = if options[:encrypt].is_a?(Hash)
                          options[:encrypt]
                        else
                          {}
                        end
  super
end

Instance Method Details

#deterministic?true | false | nil

Returns Whether the field should be encrypted using a deterministic encryption algorithm; if not specified, nil is returned.

Returns:

  • (true | false | nil)

    Whether the field should be encrypted using a deterministic encryption algorithm; if not specified, nil is returned.



19
20
21
# File 'lib/mongoid/fields/encrypted.rb', line 19

def deterministic?
  @encryption_options[:deterministic]
end

#key_idString | nil

Returns The key id to use for encryption; if not specified, nil is returned.

Returns:

  • (String | nil)

    The key id to use for encryption; if not specified, nil is returned.



25
26
27
# File 'lib/mongoid/fields/encrypted.rb', line 25

def key_id
  @encryption_options[:key_id]
end

#key_name_fieldString | nil

Returns The name of the field that contains the key alt name to use for encryption; if not specified, nil is returned.

Returns:

  • (String | nil)

    The name of the field that contains the key alt name to use for encryption; if not specified, nil is returned.



31
32
33
# File 'lib/mongoid/fields/encrypted.rb', line 31

def key_name_field
  @encryption_options[:key_name_field]
end

#set_key_id(key_id) ⇒ Object

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.

Override the key_id for the field.

This method is solely for testing purposes and should not be used in the application code. The schema_map is generated very early in the application lifecycle, and overriding the key_id after that will not have any effect.



43
44
45
# File 'lib/mongoid/fields/encrypted.rb', line 43

def set_key_id(key_id)
  @encryption_options[:key_id] = key_id
end