Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ActiveRecord
- module Validations
- def self.append_features(base) #:nodoc:
- super
- base.extend ClassMethods
- end
- module ClassMethods
- # Automatically defines length limits for columns that have such limits in the DB
- def columns_with_limit
- return @limit_columns if @limit_columns
- @limit_columns = []
- begin
- content_columns.find_all { |col| col.type == :string and col.limit }.each do |col|
- @limit_columns << [col.name, col.limit]
- end if content_columns
- return @limit_columns
- end
- return []
- end
- # Automatically defines validate_presence_of for DB columns with NOT NULL and no default
- def mandatory_content_columns
- return @mandatory_content_columns if @mandatory_content_columns
- @mandatory_content_columns = []
- begin
- content_columns.find_all { |col| !col.null and col.default.nil? }.each do |col|
- @mandatory_content_columns << col.name
- end if content_columns
- return @mandatory_content_columns
- end
- return []
- end
- end
- end
Add Comment
Please, Sign In to add comment