module Thyng::CryptedAspect

Public Instance Methods

crypted_accessor(aspect) click to toggle source
# File lib/thyng/crypted_aspect.rb, line 5
def crypted_accessor(aspect)
  crypted_aspect = "crypted_#{aspect}"
  aspect_accessor crypted_aspect

  define_method "#{aspect}=", ->(value) {
    send "#{crypted_aspect}=", BCrypt::Password.create(value)
  }

  define_method aspect, -> () {
    BCrypt::Password.new send(crypted_aspect)
  }

  define_method "check_#{aspect}?", -> (test_value) {
    send(aspect) == test_value
  }
end