123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::Fields::Encrypted

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Standard, Forwardable
Instance Chain:
self, Standard
Inherits: Mongoid::Fields::Standard
Defined in: lib/mongoid/fields/encrypted.rb

Overview

Represents a field that should be encrypted.

Class Method Summary

Standard - Inherited

.new

Create the new field with a name and optional additional options.

Instance Attribute Summary

Standard - Inherited

#default_val

Defines the behavior for defined fields in the document.

#foreign_key?

Is this field a foreign key?

#label

Defines the behavior for defined fields in the document.

#lazy?

Does this field do lazy default evaluation?

#localize_present?

Is the localized field enforcing values to be present?

#localized?

Is the field localized or not?

#name

Defines the behavior for defined fields in the document.

#object_id_field?

Is the field a BSON::ObjectId?

#options

Defines the behavior for defined fields in the document.

#pre_processed?

Does the field pre-process its default value?

Instance Method Summary

Standard - Inherited

#add_atomic_changes

Adds the atomic changes for this type of resizable field.

#association

Get the metadata for the field if its a foreign key.

#eval_default

Evaluate the default value and return it.

#type

Get the type of this field - inferred from the class name.

#default_name

Get the name of the default method for this field.

#define_default_method

Define the method for getting the default on the document.

#evaluate_default_proc

Evaluate the default proc.

#evaluated_default

Get the evaluated default.

#included?

Is the field included in the fields that were returned from the database? We can apply the default if:

#serialize_default

This is used when default values need to be serialized.

Constructor Details

.new(name, options = {}) ⇒ Encrypted

[ GitHub ]

  
# 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 Attribute Details

#deterministic?true | false | nil (readonly)

Returns:

  • (true | false | nil)

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

[ GitHub ]

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

def deterministic?
  @encryption_options[:deterministic]
end

Instance Method Details

#key_idString | nil

Returns:

  • (String | nil)

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

[ GitHub ]

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

def key_id
  @encryption_options[:key_id]
end

#key_name_fieldString | nil

Returns:

  • (String | nil)

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

[ GitHub ]

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

def key_name_field
  @encryption_options[:key_name_field]
end

#set_key_id(key_id)

This method is for internal use only.

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.

[ GitHub ]

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

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