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
-
#attr_encrypted?(attribute) ⇒ Boolean
Checks if an attribute has been configured to be encrypted.
-
#attr_encrypted_options ⇒ Object
Default options to use with calls to
attr_encrypted
. -
#attr_encrypted_options=(options) ⇒ Object
Sets default options to use with calls to
attr_encrypted
. -
#encrypted_attributes ⇒ Object
Contains a hash of encrypted attributes with virtual attribute names as keys and real attribute names as values.
Class Method Details
.extended(base) ⇒ Object
5 6 7 8 |
# File 'lib/attr_encrypted.rb', line 5 def self.extended(base) base. = {} 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
47 48 49 |
# File 'lib/attr_encrypted.rb', line 47 def attr_encrypted?(attribute) encrypted_attributes.keys.include?(attribute.to_s) end |
#attr_encrypted_options ⇒ Object
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 ||= superclass..nil? ? {} : superclass..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 = end |
#encrypted_attributes ⇒ Object
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 |