module Sequel::Plugins::AutoValidations::InstanceMethods

  1. lib/sequel/plugins/auto_validations.rb

Methods

Public Instance

  1. skip_auto_validations
  2. validate

Public Instance methods

skip_auto_validations(*types)

Skip the given types of auto validations on this instance inside the block.

[show source]
    # File lib/sequel/plugins/auto_validations.rb
240 def skip_auto_validations(*types)
241   types << :all if types.empty?
242   @_skip_auto_validations = types
243   yield
244 ensure
245   @_skip_auto_validations = nil
246 end
validate()

Validate the model’s auto validations columns

[show source]
    # File lib/sequel/plugins/auto_validations.rb
249 def validate
250   super
251   skip = @_skip_auto_validations || EMPTY_ARRAY
252   return if skip.include?(:all)
253   opts = model.auto_validate_options
254 
255   unless skip.include?(:no_null_byte) || (no_null_byte_columns = model.auto_validate_no_null_byte_columns).empty?
256     validates_no_null_byte(no_null_byte_columns, opts[:no_null_byte])
257   end
258 
259   unless skip.include?(:not_null)
260     not_null_method = model.auto_validate_presence? ? :validates_presence : :validates_not_null
261     unless (not_null_columns = model.auto_validate_not_null_columns).empty?
262       public_send(not_null_method, not_null_columns, opts[:not_null])
263     end
264     unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
265       public_send(not_null_method, not_null_columns, opts[:explicit_not_null])
266     end
267   end
268 
269   unless skip.include?(:max_length) || (max_length_columns = model.auto_validate_max_length_columns).empty?
270     max_length_columns.each do |col, len|
271       validates_max_length(len, col, opts[:max_length])
272     end
273   end
274 
275   unless skip.include?(:types) || !model.auto_validate_types?
276     validates_schema_types(keys, opts[:schema_types])
277 
278     unless skip.include?(:max_value) || ((max_value_columns = model.auto_validate_max_value_columns).empty?)
279       max_value_columns.each do |col, max|
280         validates_max_value(max, col, opts[:max_value])
281       end
282     end
283 
284     unless skip.include?(:min_value) || ((min_value_columns = model.auto_validate_min_value_columns).empty?)
285       min_value_columns.each do |col, min|
286         validates_min_value(min, col, opts[:min_value])
287       end
288     end
289   end
290 
291   unless skip.include?(:unique)
292     unique_opts = Hash[opts[:unique]]
293     if model.respond_to?(:sti_dataset)
294       unique_opts[:dataset] = model.sti_dataset
295     end
296     model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
297   end
298 end