Sha256: 2613886c4b5864aa0a6c1849d4427136f87e3f382ac4f5191632295b56a46b02
Contents?: true
Size: 826 Bytes
Versions: 2
Compression:
Stored size: 826 Bytes
Contents
module MongoidExt module Encryptor extend ActiveSupport::Concern included do require 'encryptor' end module ClassMethods def encrypted_field(name, options = {}) key = options.delete(:key) raise ArgumentError, ":key option must be given" if key.nil? field(name, options) alias_method :"#{name}_encrypted", name define_method(name) do value = [send(:"#{name}_encrypted").to_s].pack('H*') return if value.blank? Marshal.load(::Encryptor.decrypt(value, :key => key)) end define_method("#{name}=") do |v| marshaled = Marshal.dump(v) enc_value = ::Encryptor.encrypt(marshaled, :key => key).unpack('H*')[0] write_attribute(name, enc_value) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mongoid_ext-0.7.1 | lib/mongoid_ext/encryptor.rb |
mongoid_ext-0.6.2 | lib/mongoid_ext/encryptor.rb |