Class: Mongoid::EncryptedHash

Inherits:
Hash
  • Object
show all
Includes:
EncryptedField
Defined in:
lib/mongoid-encrypted-fields/fields/encrypted_hash.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EncryptedField

#encrypted, #mongoize

Class Method Details

.convert(object) ⇒ Object

Takes an object representation (Hash or string) and converts it to an EncryptedHash.



39
40
41
42
43
44
45
46
# File 'lib/mongoid-encrypted-fields/fields/encrypted_hash.rb', line 39

def convert(object)
  case object
    when Hash
      from_hash(object)
    else
      from_hash(::YAML.load(object))
  end
end

.from_hash(h) ⇒ Object

converts from a plain Hash to an EncryptedHash



33
34
35
# File 'lib/mongoid-encrypted-fields/fields/encrypted_hash.rb', line 33

def from_hash(h)
  self[h.to_hash]
end

Instance Method Details

#raw_valueObject

Return value to be encrypted



26
27
28
# File 'lib/mongoid-encrypted-fields/fields/encrypted_hash.rb', line 26

def raw_value
  stringify_keys.to_yaml
end