Guest User

Untitled

a guest
Jun 4th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # Monkey patch for datamapper version 0.9.10
  2. #
  3. # Allow the validates_present validator
  4. # to check for blank BCryptHash passwords.
  5. #
  6. # require "dm-core"
  7. # require "dm-validations"
  8. # require "dm-types"
  9. # class User
  10. # include DataMapper::Resource
  11. # property :password, BCryptHash
  12. # validates_present :password
  13. # end
  14. #
  15. # user = User.new
  16. # user.password = nil; user.valid? => false
  17. # user.password = ""; user.valid? => false
  18. # user.password = " "; user.valid? => false
  19. # user.password = "x"; user.valid? => true
  20. # user.password = " x "; user.valid? => true
  21. # user.password == " x " => true
  22. # user.password == "x" => false
  23. #
  24.  
  25. require 'dm-types/bcrypt_hash'
  26. module DataMapper
  27. module Types
  28. class BCryptHash
  29. class << self
  30. alias_method :old_non_blank_check_self_typecast, :typecast
  31. end
  32. def self.typecast(value, property)
  33. value = nil if value.respond_to?(:blank?) && value.blank?
  34. old_non_blank_check_self_typecast(value, property)
  35. end
  36. end
  37. end
  38. end
Add Comment
Please, Sign In to add comment