module Sequel::Plugins::AutoValidations::ClassMethods

Attributes

auto_validate_presence_columns[R]

The columns with automatic presence validations

auto_validate_unique_columns[R]

The columns or sets of columns with automatic unique validations

Public Instance Methods

auto_validate_types?() click to toggle source

Whether to automatically validate schema types for all columns

# File lib/sequel/plugins/auto_validations.rb, line 66
def auto_validate_types?
  @auto_validate_types
end
skip_auto_validations(type) click to toggle source

Skip automatic validations for the given validation type (:presence, :types, :unique). If :all is given as the type, skip all auto validations.

# File lib/sequel/plugins/auto_validations.rb, line 72
def skip_auto_validations(type)
  if type == :all
    [:presence, :types, :unique].each{|v| skip_auto_validations(v)}
  elsif type == :types
    @auto_validate_types = false
  else
    send("auto_validate_#{type}_columns").clear
  end
end

Private Instance Methods

setup_auto_validations() click to toggle source

Parse the database schema and indexes and record the columns to automatically validate.

# File lib/sequel/plugins/auto_validations.rb, line 85
def setup_auto_validations
  @auto_validate_presence_columns = db_schema.select{|col, sch| sch[:allow_null] == false && sch[:ruby_default].nil?}.map{|col, sch| col} - Array(primary_key)
  @auto_validate_unique_columns = if db.respond_to?(:indexes) 
    db.indexes(dataset.first_source_table).select{|name, idx| idx[:unique] == true}.map{|name, idx| idx[:columns]}
  else
    []
  end
end