Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. class Client
  2. require 'data_mapper'
  3.  
  4. include DataMapper::Resource
  5.  
  6. property :id, Serial
  7. property :name, String
  8. property :type, String
  9.  
  10. validates_with_method :name, :method => :valid_name?
  11. validates_with_method :type, :method => :valid_type?
  12.  
  13. private
  14.  
  15. def valid_name?
  16. !@name.nil? && !@name.empty?
  17. end
  18.  
  19. def valid_type?
  20. !@type.nil? && !@type.empty?
  21. end
  22. end
  23.  
  24. class Employee
  25. include DataMapper::Resource
  26. include LumberYardConstants
  27.  
  28. property :id, Serial
  29. property :first_name, String
  30. property :last_name, String
  31. property :username, String
  32. property :employee_type, String
  33.  
  34. validates_with_method :first_name, :method => :valid_name_attributes?
  35. validates_with_method :last_name, :method => :valid_name_attributes?
  36. validates_with_method :username, :method => :valid_username?
  37. validates_with_method :employee_type, :method => :valid_employee_type?
  38.  
  39. private
  40.  
  41. def valid_employee_type?
  42. EMPLOYEE_TYPES.include?(@employee_type)
  43. end
  44.  
  45. def valid_employee_fields?
  46. valid_name_attributes? && valid_username?
  47. end
  48.  
  49. def valid_name_attributes?
  50. !@last_name.nil? && !@last_name.empty?
  51. !@first_name.nil? && !@first_name.empty?
  52. end
  53.  
  54. def valid_username?
  55. !@username.nil? && !@username.empty?
  56. end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement