Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. module Validation
  2. module ClassMethods
  3. def validates_uniqueness_of(*atts)
  4. opts = {
  5. :message => 'is already taken',
  6. }.merge!(atts.extract_options!)
  7.  
  8. validates_each(*atts) do |o, a, v|
  9. o.errors[a] << opts[:message] unless v && !v.blank? && !o.class[a => v]
  10. end
  11. end
  12. end
  13. end
  14.  
  15. class User < Sequel::Model
  16.  
  17. validates do
  18. presence_of :username
  19. length_of :username, :within => 1..32
  20. format_of :username, :with => /^\w+$/
  21.  
  22. presence_of :password
  23. length_of :password, :is => 40
  24.  
  25. uniqueness_of :email
  26. end
  27.  
  28. end
Add Comment
Please, Sign In to add comment