Class: DataMapper::Property::BCryptHash
- Inherits:
-
String
- Object
- String
- DataMapper::Property::BCryptHash
- Defined in:
- lib/dm-types/bcrypt_hash.rb
Instance Method Summary collapse
Instance Method Details
#dump(value) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/dm-types/bcrypt_hash.rb', line 15 def dump(value) hash = typecast(value) return if hash.nil? hash_string = hash.to_s hash_string.encode!('UTF-8') if hash_string.respond_to?(:encode!) hash_string end |
#load(value) ⇒ Object
11 12 13 |
# File 'lib/dm-types/bcrypt_hash.rb', line 11 def load(value) typecast(value) end |
#typecast(value) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/dm-types/bcrypt_hash.rb', line 24 def typecast(value) return value if value.nil? || value.kind_of?(BCrypt::Password) BCrypt::Password.new(value) rescue BCrypt::Errors::InvalidHash BCrypt::Password.create(value) end |