Class: DataMapper::Property::BCryptHash

Inherits:
String
  • Object
show all
Defined in:
lib/dm-types/bcrypt_hash.rb

Instance Method Summary collapse

Instance Method Details

#dump(value) ⇒ Object



24
25
26
# File 'lib/dm-types/bcrypt_hash.rb', line 24

def dump(value)
  load(value)
end

#load(value) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/dm-types/bcrypt_hash.rb', line 14

def load(value)
  unless value.nil?
    begin
      primitive?(value) ? value : BCrypt::Password.new(value)
    rescue BCrypt::Errors::InvalidHash
      BCrypt::Password.create(value, :cost => BCrypt::Engine::DEFAULT_COST)
    end
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/dm-types/bcrypt_hash.rb', line 10

def primitive?(value)
  value.kind_of?(BCrypt::Password)
end

#typecast_to_primitive(value) ⇒ Object



28
29
30
# File 'lib/dm-types/bcrypt_hash.rb', line 28

def typecast_to_primitive(value)
  load(value)
end