Module: AttrEncrypted

Defined in:
lib/attr_encrypted.rb,
lib/attr_encrypted/adapters/sequel.rb,
lib/attr_encrypted/adapters/data_mapper.rb,
lib/attr_encrypted/adapters/active_record.rb

Defined Under Namespace

Modules: Adapters

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
# File 'lib/attr_encrypted.rb', line 5

def self.extended(base)
  base.attr_encrypted_options = {}
  base.instance_variable_set('@encrypted_attributes', {})
end

Instance Method Details

#attr_encrypted?(attribute) ⇒ Boolean

Checks if an attribute has been configured to be encrypted

Example

class User
  attr_accessor :name
  attr_encrypted :email
end

User.attr_encrypted?(:name) # false
User.attr_encrypted?(:email) # true

Returns:

  • (Boolean)


47
48
49
# File 'lib/attr_encrypted.rb', line 47

def attr_encrypted?(attribute)
  encrypted_attributes.keys.include?(attribute.to_s)
end

#attr_encrypted_optionsObject

Default options to use with calls to attr_encrypted.

It will inherit existing options from its parent class



13
14
15
# File 'lib/attr_encrypted.rb', line 13

def attr_encrypted_options
  @attr_encrypted_options ||= superclass.attr_encrypted_options.nil? ? {} : superclass.attr_encrypted_options.dup
end

#attr_encrypted_options=(options) ⇒ Object

Sets default options to use with calls to attr_encrypted.



18
19
20
# File 'lib/attr_encrypted.rb', line 18

def attr_encrypted_options=(options)
  @attr_encrypted_options = options
end

#encrypted_attributesObject

Contains a hash of encrypted attributes with virtual attribute names as keys and real attribute names as values

Example

class User
  attr_encrypted :email
end

User.encrypted_attributes # { 'email' => 'encrypted_email' }


32
33
34
# File 'lib/attr_encrypted.rb', line 32

def encrypted_attributes
  @encrypted_attributes ||= superclass.encrypted_attributes.nil? ? {} : superclass.encrypted_attributes.dup
end