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.



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

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.



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

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.



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

def key_id
  @encryption_options[:key_id]
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.



36
37
38
# File 'lib/mongoid/fields/encrypted.rb', line 36

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