Module: Sequel::Plugins::AutoValidations::InstanceMethods

Defined in:
lib/sequel/plugins/auto_validations.rb

Instance Method Summary collapse

Instance Method Details

#validateObject

Validate the model’s auto validations columns



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/sequel/plugins/auto_validations.rb', line 128

def validate
  super
  unless (not_null_columns = model.auto_validate_not_null_columns).empty?
    if model.auto_validate_presence?
      validates_presence(not_null_columns)
    else
      validates_not_null(not_null_columns)
    end
  end
  unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
    if model.auto_validate_presence?
      validates_presence(not_null_columns, :allow_missing=>true)
    else
      validates_not_null(not_null_columns, :allow_missing=>true)
    end
  end
  unless (max_length_columns = model.auto_validate_max_length_columns).empty?
    max_length_columns.each do |col, len|
      validates_max_length(len, col, :allow_nil=>true)
    end
  end

  validates_schema_types if model.auto_validate_types?

  unique_opts = {}
  if model.respond_to?(:sti_dataset)
    unique_opts[:dataset] = model.sti_dataset
  end
  model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
end