Guest User

Untitled

a guest
Jul 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. module ActiveRecord
  2. module Validations
  3. def self.append_features(base) #:nodoc:
  4. super
  5. base.extend ClassMethods
  6. end
  7.  
  8. module ClassMethods
  9. # Automatically defines length limits for columns that have such limits in the DB
  10. def columns_with_limit
  11. return @limit_columns if @limit_columns
  12. @limit_columns = []
  13. begin
  14. content_columns.find_all { |col| col.type == :string and col.limit }.each do |col|
  15. @limit_columns << [col.name, col.limit]
  16. end if content_columns
  17. return @limit_columns
  18. end
  19. return []
  20. end
  21.  
  22. # Automatically defines validate_presence_of for DB columns with NOT NULL and no default
  23. def mandatory_content_columns
  24. return @mandatory_content_columns if @mandatory_content_columns
  25. @mandatory_content_columns = []
  26. begin
  27. content_columns.find_all { |col| !col.null and col.default.nil? }.each do |col|
  28. @mandatory_content_columns << col.name
  29. end if content_columns
  30. return @mandatory_content_columns
  31. end
  32. return []
  33. end
  34.  
  35. end
  36. end
Add Comment
Please, Sign In to add comment