0
def self.included(base)
0
base.extend(ClassMethods)
0
- # Auto generate validations for a given property. This will only occur
0
- # if the option :auto_validations is true or undefined.
0
+ # Auto-generate validations for a given property. This will only occur
0
+ # if the option :auto_validation is either true or left undefined.
0
# ==== Triggers that generate validator creation
0
- # Setting the option :nullable to false causes a validates_presence_of
0
- # validator to be automatically created on the property
0
+ # Setting the option :nullable to false causes a
0
+ # validates_presence_of validator to be automatically created on
0
# :size => 20 or :length => 20
0
- # Setting the option :size or :length causes a validates_length_of
0
- # validator to be automatically created on the property. If the value
0
- # is a Fixnum the validation will set :maximum => value if the value
0
- # is a Range the validation will set :within => value
0
+ # Setting the option :size or :length causes a validates_length_of
0
+ # validator to be automatically created on the property. If the
0
+ # value is a Fixnum the validation will set :maximum => value if
0
+ # the value is a Range the validation will set :within => value
0
# :format => :predefined / lambda / Proc
0
- # Setting the :format option causes a validates_format_of validatior
0
- # to be automatically created on the property
0
+ # Setting the :format option causes a validates_format_of
0
+ # validator to be automatically created on the property
0
def auto_generate_validations(property)
0
property.options[:auto_validation] = true unless property.options.has_key?(:auto_validation)
0
return unless property.options[:auto_validation]
0
opts[:context] = property.options[:validates] if property.options.has_key?(:validates)
0
if property.options.has_key?(:nullable) && !property.options[:nullable]
0
- validates_presence_of property.name, opts
0
+ validates_present property.name, opts
0
if property.type == String
0
if property.options.has_key?(:length) || property.options.has_key?(:size)
0
len = property.options.has_key?(:length) ? property.options[:length] : property.options[:size]
0
opts[:within] = len if len.is_a?(Range)
0
- opts[:maximum] = len unless len.is_a?(Range)
0
- opts[:allow_nil] = property.options[:nullable] if property.options.has_key?(:nullable)
0
- validates_length_of property.name, opts
0
+ opts[:maximum] = len unless len.is_a?(Range)
0
+ opts[:allow_nil] = property.options[:nullable] if property.options.has_key?(:nullable)
0
+ validates_length property.name, opts
0
opts[:maximum] = 50 #default string size
0
- validates_length_of property.name, opts
0
+ validates_length property.name, opts
0
if property.options.has_key?(:format)
0
opts[:with] = property.options[:format]
0
- validates_format_of property.name, opts
0
+ validates_format property.name, opts
0
if property.options.has_key?(:unique)
0
value = property.options[:unique]
0
@@ -69,14 +68,15 @@ module DataMapper
0
scope << value if value.is_a?(Symbol)
0
opts[:scope] = scope if scope.length > 0
0
if value.is_a?(TrueClass) || scope.length > 0
0
- validates_uniqueness_of property.name, opts
0
+ validates_is_unique property.name, opts
0
+ end # module ClassMethods
0
+ end # module AutoValidate
0
+end # module DataMapper