Module: Sequel::Plugins::AutoValidations::InstanceMethods
- Defined in:
- lib/sequel/plugins/auto_validations.rb
Instance Method Summary collapse
-
#skip_auto_validations(*types) ⇒ Object
Skip the given types of auto validations on this instance inside the block.
-
#validate ⇒ Object
Validate the model’s auto validations columns.
Instance Method Details
#skip_auto_validations(*types) ⇒ Object
Skip the given types of auto validations on this instance inside the block.
240 241 242 243 244 245 246 |
# File 'lib/sequel/plugins/auto_validations.rb', line 240 def skip_auto_validations(*types) types << :all if types.empty? @_skip_auto_validations = types yield ensure @_skip_auto_validations = nil end |
#validate ⇒ Object
Validate the model’s auto validations columns
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/sequel/plugins/auto_validations.rb', line 249 def validate super skip = @_skip_auto_validations || EMPTY_ARRAY return if skip.include?(:all) opts = model. unless skip.include?(:no_null_byte) || (no_null_byte_columns = model.auto_validate_no_null_byte_columns).empty? validates_no_null_byte(no_null_byte_columns, opts[:no_null_byte]) end unless skip.include?(:not_null) not_null_method = model.auto_validate_presence? ? :validates_presence : :validates_not_null unless (not_null_columns = model.auto_validate_not_null_columns).empty? public_send(not_null_method, not_null_columns, opts[:not_null]) end unless (not_null_columns = model.auto_validate_explicit_not_null_columns).empty? public_send(not_null_method, not_null_columns, opts[:explicit_not_null]) end end unless skip.include?(:max_length) || (max_length_columns = model.auto_validate_max_length_columns).empty? max_length_columns.each do |col, len| validates_max_length(len, col, opts[:max_length]) end end unless skip.include?(:types) || !model.auto_validate_types? validates_schema_types(keys, opts[:schema_types]) unless skip.include?(:max_value) || ((max_value_columns = model.auto_validate_max_value_columns).empty?) max_value_columns.each do |col, max| validates_max_value(max, col, opts[:max_value]) end end unless skip.include?(:min_value) || ((min_value_columns = model.auto_validate_min_value_columns).empty?) min_value_columns.each do |col, min| validates_min_value(min, col, opts[:min_value]) end end end unless skip.include?(:unique) unique_opts = Hash[opts[:unique]] 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 end |