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.



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

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



31
32
33
# File 'lib/mongoid-encrypted-fields/fields/encrypted_hash.rb', line 31

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

Instance Method Details

#raw_valueObject

Return value to be encrypted



24
25
26
# File 'lib/mongoid-encrypted-fields/fields/encrypted_hash.rb', line 24

def raw_value
  to_yaml
end