module NoBrainer::Document::Validation::Core::ClassMethods

Public Instance Methods

field(attr, options={}) click to toggle source
Calls superclass method
# File lib/no_brainer/document/validation/core.rb, line 29
def field(attr, options={})
  super

  shorthands = SHORTHANDS
  shorthands = shorthands.merge(:required => :not_null) if options[:type] == NoBrainer::Boolean
  shorthands.each { |k,v| validates(attr, v => options[k]) if options.key?(k) }

  validates(attr, options[:validates]) if options[:validates]
  validates(attr, :length => { :minimum => options[:min_length] }) if options[:min_length]
  validates(attr, :length => { :maximum => options[:max_length] }) if options[:max_length]
end