Class: PasswordTypecaster

Inherits:
Typecaster show all
Defined in:
lib/type_casters.rb

Overview

Casts a value to a password by encoding the passed value

Instance Method Summary collapse

Methods inherited from Typecaster

registered_typecasters, typecaster_for

Instance Method Details

#message_encryptorObject



88
89
90
# File 'lib/type_casters.rb', line 88

def message_encryptor
  @message_encryptor ||= ActiveSupport::MessageEncryptor.new(Settler.password_secret || '01234567890123456789012345678901')
end

#typeObject



74
# File 'lib/type_casters.rb', line 74

def type; 'password' end

#typecast(value) ⇒ Object



76
77
78
# File 'lib/type_casters.rb', line 76

def typecast(value)
  message_encryptor.decrypt_and_verify(value.to_s)
end

#typecast_on_write(value) ⇒ Object



80
81
82
# File 'lib/type_casters.rb', line 80

def typecast_on_write(value)
  message_encryptor.encrypt_and_sign(value.to_s)
end

#typecast_on_write?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/type_casters.rb', line 84

def typecast_on_write?
  true # force typecast on write
end