Skip to content

Instantly share code, notes, and snippets.

@aflatter
Created March 12, 2015 14:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aflatter/d47a8c6ec1c38ce418ae to your computer and use it in GitHub Desktop.
Save aflatter/d47a8c6ec1c38ce418ae to your computer and use it in GitHub Desktop.
SCrypt::Password attribute type for Virtus
require 'scrypt'
module Virtus
class Attribute
class Password < ::Virtus::Attribute
primitive SCrypt::Password
def coerce(value)
value ? SCrypt::Password.new(value) : nil
rescue SCrypt::Errors::InvalidHash
nil
end
def value_coerced?(value)
value.instance_of?(SCrypt::Password)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment