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
197 def skip_auto_validations(*types)
198   types << :all if types.empty?
199   @_skip_auto_validations = types
200   yield
201 ensure
202   @_skip_auto_validations = nil
203 end
validate()

Validate the model's auto validations columns

[show source]
    # File lib/sequel/plugins/auto_validations.rb
206 def validate
207   super
208   skip = @_skip_auto_validations || EMPTY_ARRAY
209   return if skip.include?(:all)
210   opts = model.auto_validate_options
211 
212 
213   unless skip.include?(:not_null)
214     not_null_method = model.auto_validate_presence? ? :validates_presence : :validates_not_null
215     unless (not_null_columns = model.auto_validate_not_null_columns).empty?
216       public_send(not_null_method, not_null_columns, opts[:not_null])
217     end
218     unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty?
219       public_send(not_null_method, not_null_columns, opts[:explicit_not_null])
220     end
221   end
222 
223   unless skip.include?(:max_length) || (max_length_columns = model.auto_validate_max_length_columns).empty?
224     max_length_columns.each do |col, len|
225       validates_max_length(len, col, opts[:max_length])
226     end
227   end
228 
229   unless skip.include?(:types) || !model.auto_validate_types?
230     validates_schema_types(keys, opts[:schema_types])
231   end
232 
233   unless skip.include?(:unique)
234     unique_opts = Hash[opts[:unique]]
235     if model.respond_to?(:sti_dataset)
236       unique_opts[:dataset] = model.sti_dataset
237     end
238     model.auto_validate_unique_columns.each{|cols| validates_unique(cols, unique_opts)}
239   end
240 end