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
214 def skip_auto_validations(*types)
215   types << :all if types.empty?
216   @_skip_auto_validations = types
217   yield
218 ensure
219   @_skip_auto_validations = nil
220 end
validate()

Validate the model's auto validations columns

[show source]
    # File lib/sequel/plugins/auto_validations.rb
223 def validate
224   super
225   skip = @_skip_auto_validations || EMPTY_ARRAY
226   return if skip.include?(:all)
227   opts = model.auto_validate_options
228 
229   unless skip.include?(:no_null_byte) || (no_null_byte_columns = model.auto_validate_no_null_byte_columns).empty?
230     validates_no_null_byte(no_null_byte_columns, opts[:no_null_byte])
231   end
232 
233   unless skip.include?(:not_null)
234     not_null_method = model.auto_validate_presence? ? :validates_presence : :validates_not_null
235     unless (not_null_columns = model.auto_validate_not_null_columns).empty?
236       public_send(not_null_method, not_null_columns, opts[:not_null])
237     end
238     unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
239       public_send(not_null_method, not_null_columns, opts[:explicit_not_null])
240     end
241   end
242 
243   unless skip.include?(:max_length) || (max_length_columns = model.auto_validate_max_length_columns).empty?
244     max_length_columns.each do |col, len|
245       validates_max_length(len, col, opts[:max_length])
246     end
247   end
248 
249   unless skip.include?(:types) || !model.auto_validate_types?
250     validates_schema_types(keys, opts[:schema_types])
251   end
252 
253   unless skip.include?(:unique)
254     unique_opts = Hash[opts[:unique]]
255     if model.respond_to?(:sti_dataset)
256       unique_opts[:dataset] = model.sti_dataset
257     end
258     model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
259   end
260 end