module Sequel::Plugins::AutoValidations::ClassMethods
Attributes
auto_validate_explicit_not_null_columns[R]
The columns with automatic not_null validations for columns present in the values.
auto_validate_not_null_columns[R]
The columns with automatic not_null validations
auto_validate_unique_columns[R]
The columns or sets of columns with automatic unique validations
Public Instance Methods
auto_validate_presence?()
click to toggle source
Whether to use a presence validation for not null columns
# File lib/sequel/plugins/auto_validations.rb, line 87 def auto_validate_presence? @auto_validate_presence end
auto_validate_presence_columns()
click to toggle source
REMOVE40
# File lib/sequel/plugins/auto_validations.rb, line 81 def auto_validate_presence_columns Sequel::Deprecation.deprecate('Model.auto_validate_presence_columns', 'Please switch to auto_validate_not_null_columns') auto_validate_not_null_columns end
auto_validate_types?()
click to toggle source
Whether to automatically validate schema types for all columns
# File lib/sequel/plugins/auto_validations.rb, line 92 def auto_validate_types? @auto_validate_types end
skip_auto_validations(type)
click to toggle source
Skip automatic validations for the given validation type (:not_null, :types, :unique). If :all is given as the type, skip all auto validations.
# File lib/sequel/plugins/auto_validations.rb, line 98 def skip_auto_validations(type) if type == :all [:not_null, :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 111 def setup_auto_validations not_null_cols, explicit_not_null_cols = db_schema.select{|col, sch| sch[:allow_null] == false}.partition{|col, sch| sch[:ruby_default].nil?}.map{|cs| cs.map{|col, sch| col}} @auto_validate_not_null_columns = not_null_cols - Array(primary_key) explicit_not_null_cols += Array(primary_key) @auto_validate_explicit_not_null_columns = explicit_not_null_cols.uniq @auto_validate_unique_columns = if db.supports_index_parsing? db.indexes(dataset.first_source_table).select{|name, idx| idx[:unique] == true}.map{|name, idx| idx[:columns]} else [] end end