Module: NoBrainer::Document::Validation::Core::ClassMethods

Defined in:
lib/no_brainer/document/validation/core.rb

Instance Method Summary collapse

Instance Method Details

#field(attr, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# 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