Module: Mongoid::Config::Encryption Private

Extended by:
Encryption
Included in:
Mongoid::Config, Encryption
Defined in:
lib/mongoid/config/encryption.rb

Overview

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

This module contains the logic for configuring Client Side Field Level automatic encryption.

Instance Method Summary collapse

Instance Method Details

#encryption_schema_map(default_database, models = ::Mongoid.models) ⇒ Hash

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.

Generate the encryption schema map for the provided models.

Parameters:

  • default_database (String)

    The default database name.

  • models (Array<Mongoid::Document>) (defaults to: ::Mongoid.models)

    The models to generate the schema map for. Defaults to all models in the application.

Returns:

  • (Hash)

    The encryption schema map.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mongoid/config/encryption.rb', line 23

def encryption_schema_map(default_database, models = ::Mongoid.models)
  visited = Set.new
  models.each_with_object({}) do |model, map|
    next if visited.include?(model)
    visited << model
    next if model.embedded?
    next unless model.encrypted?

    database = model.storage_options.fetch(:database) { default_database }
    key = "#{database}.#{model.collection_name}"
    props = (model).merge(properties_for(model, visited))
    map[key] = props unless props.empty?
  end
end