/vendor/gems/gems/dm-validations-0.10.1/spec/fixtures/bill_of_landing.rb

https://github.com/bradgessler/jack · Ruby · 42 lines · 22 code · 9 blank · 11 comment · 1 complexity · dbaa658b4cd4eb29654a3ada42295375 MD5 · raw file

  1. # -*- coding: utf-8 -*-
  2. module DataMapper
  3. module Validate
  4. module Fixtures
  5. class BillOfLading
  6. #
  7. # Behaviors
  8. #
  9. include DataMapper::Resource
  10. #
  11. # Properties
  12. #
  13. property :id, Serial
  14. property :doc_no, String, :auto_validation => false
  15. property :email, String, :auto_validation => false
  16. property :username, String, :auto_validation => false
  17. property :url, String, :auto_validation => false
  18. property :code, String, :auto_validation => false, :default => "123456"
  19. #
  20. # Validations
  21. #
  22. # this is a trivial example
  23. validates_format :doc_no, :with => lambda { |code|
  24. code =~ /\AA\d{4}\z/ || code =~ /\A[B-Z]\d{6}X12\z/
  25. }
  26. validates_format :email, :as => :email_address
  27. validates_format :url, :as => :url, :allow_nil => false
  28. validates_format :username, :with => /[a-z]/, :message => 'Username must have at least one letter', :allow_nil => true
  29. validates_format :code, :with => /\d{5,6}/, :message => 'Code format is invalid'
  30. end
  31. end # Fixtures
  32. end # Validate
  33. end # DataMapper