Sha256: 64e94dfc2045baad162b46a2b13de54601ae6fcac3178fb687038b87d98bef05
Contents?: true
Size: 944 Bytes
Versions: 6
Compression:
Stored size: 944 Bytes
Contents
module Vidibus module Secure module Mongoid extend ActiveSupport::Concern module ClassMethods # Sets encrypted attributes. def attr_encrypted(*args) key = ENV["VIDIBUS_SECURE_KEY"] options = args.extract_options! for field in args # Define Mongoid field encrypted_field = "#{field}_encrypted" self.send(:field, encrypted_field, :type => BSON::Binary) # Define setter class_eval <<-EOV def #{field}=(value) self.#{encrypted_field} = value ? Vidibus::Secure.encrypt(value, "#{key}") : nil end EOV # Define getter class_eval <<-EOV def #{field} Vidibus::Secure.decrypt(#{encrypted_field}, "#{key}") if #{encrypted_field} end EOV end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems