Sha256: 8c6980d1c9815f5a7eadc085404f26e36bc96a651c87d3d8a8202debac24a72f

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

#
# DEPRECATED !!!
#
module MongoMapper
  module Plugins
    module EncryptedKey
      extend ActiveSupport::Concern

      COERCION_MAP = {
        String     => :string,
        Integer    => :integer,
        Float      => :float,
        BigDecimal => :decimal,
        DateTime   => :datetime,
        Time       => :time,
        Date       => :date,
        Boolean    => :boolean,
        Hash       => :json
      }

      module ClassMethods
        def encrypted_key(key_name, type, full_options={})
          full_options = full_options.is_a?(Hash) ? full_options.dup : {}
          options      = full_options.delete(:encrypted) || {}
          # Support overriding the name of the decrypted attribute
          encrypted_key_name = options.delete(:encrypt_as) || "encrypted_#{key_name}"
          options[:type]     = COERCION_MAP[type] unless [:yaml, :json].include?(options[:type])

          raise(ArgumentError, "Invalid type: #{type.inspect}. Valid types: #{COERCION_MAP.keys.join(',')}") unless options[:type]

          SymmetricEncryption::Generator.generate_decrypted_accessors(self, key_name, encrypted_key_name, options)

          key(encrypted_key_name, String, full_options)
        end

      end

    end
  end
end

MongoMapper::Document.plugin(MongoMapper::Plugins::EncryptedKey)
MongoMapper::EmbeddedDocument.plugin(MongoMapper::Plugins::EncryptedKey)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
symmetric-encryption-4.0.0 lib/symmetric_encryption/extensions/mongo_mapper/plugins/encrypted_key.rb
symmetric-encryption-4.0.0.beta3 lib/symmetric_encryption/extensions/mongo_mapper/plugins/encrypted_key.rb