Sha256: 9bb901c8c1b6b26480eeca7a61155bae288c15ce976bbfd4a41127202f2e76e1

Contents?: true

Size: 606 Bytes

Versions: 1

Compression:

Stored size: 606 Bytes

Contents

require 'active_support/all'
require 'gibberish'
require 'mongoid'

module Mongoid
  class EncryptedString < String
    def mongoize
      self.class.mongoize(self)
    end

    class << self
      attr_accessor :key

      def mongoize(string)
        aes.encrypt(string)
      end

      def demongoize(string)
        return if string.nil?
        
        new(aes.decrypt(string))
      end

      def config
        self
      end

    private
      def aes
        @aes ||= Gibberish::AES.new(key || raise(StandardError, "Mongoid::EncryptedString.config.key is not set"))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-encrypted_string-0.1.0 lib/mongoid/encrypted_string.rb