Module: Sequel::Plugins::AutoValidations::ClassMethods

Defined in:
lib/sequel/plugins/auto_validations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#auto_validate_explicit_not_null_columnsObject (readonly)

The columns with automatic not_null validations for columns present in the values.



141
142
143
# File 'lib/sequel/plugins/auto_validations.rb', line 141

def auto_validate_explicit_not_null_columns
  @auto_validate_explicit_not_null_columns
end

#auto_validate_max_length_columnsObject (readonly)

The columns or sets of columns with automatic max_length validations, as an array of pairs, with the first entry being the column name and second entry being the maximum length.



145
146
147
# File 'lib/sequel/plugins/auto_validations.rb', line 145

def auto_validate_max_length_columns
  @auto_validate_max_length_columns
end

#auto_validate_max_value_columnsObject (readonly)

The columns with automatch max value validations, as an array of pairs, with the first entry being the column name and second entry being the maximum value.



149
150
151
# File 'lib/sequel/plugins/auto_validations.rb', line 149

def auto_validate_max_value_columns
  @auto_validate_max_value_columns
end

#auto_validate_min_value_columnsObject (readonly)

The columns with automatch min value validations, as an array of pairs, with the first entry being the column name and second entry being the minimum value.



153
154
155
# File 'lib/sequel/plugins/auto_validations.rb', line 153

def auto_validate_min_value_columns
  @auto_validate_min_value_columns
end

#auto_validate_no_null_byte_columnsObject (readonly)

The columns with automatic no_null_byte validations



135
136
137
# File 'lib/sequel/plugins/auto_validations.rb', line 135

def auto_validate_no_null_byte_columns
  @auto_validate_no_null_byte_columns
end

#auto_validate_not_null_columnsObject (readonly)

The columns with automatic not_null validations



138
139
140
# File 'lib/sequel/plugins/auto_validations.rb', line 138

def auto_validate_not_null_columns
  @auto_validate_not_null_columns
end

#auto_validate_optionsObject (readonly)

Inherited options



159
160
161
# File 'lib/sequel/plugins/auto_validations.rb', line 159

def auto_validate_options
  @auto_validate_options
end

#auto_validate_unique_columnsObject (readonly)

The columns or sets of columns with automatic unique validations



156
157
158
# File 'lib/sequel/plugins/auto_validations.rb', line 156

def auto_validate_unique_columns
  @auto_validate_unique_columns
end

Instance Method Details

#auto_validate_presence?Boolean

Whether to use a presence validation for not null columns

Returns:

  • (Boolean)


175
176
177
# File 'lib/sequel/plugins/auto_validations.rb', line 175

def auto_validate_presence?
  @auto_validate_presence
end

#auto_validate_types?Boolean

Whether to automatically validate schema types for all columns

Returns:

  • (Boolean)


180
181
182
# File 'lib/sequel/plugins/auto_validations.rb', line 180

def auto_validate_types?
  @auto_validate_types
end

#freezeObject

Freeze auto_validation settings when freezing model class.



185
186
187
188
189
190
191
192
193
194
195
# File 'lib/sequel/plugins/auto_validations.rb', line 185

def freeze
  @auto_validate_no_null_byte_columns.freeze
  @auto_validate_not_null_columns.freeze
  @auto_validate_explicit_not_null_columns.freeze
  @auto_validate_max_length_columns.freeze
  @auto_validate_max_value_columns.freeze
  @auto_validate_min_value_columns.freeze
  @auto_validate_unique_columns.freeze

  super
end

#skip_auto_validations(type) ⇒ Object

Skip automatic validations for the given validation type (:not_null, :no_null_byte, :types, :unique, :max_length, :max_value, :min_value). If :all is given as the type, skip all auto validations.

Skipping types validation automatically skips max_value and min_value validations, since those validations require valid types.



203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/sequel/plugins/auto_validations.rb', line 203

def skip_auto_validations(type)
  case type
  when :all
    [:not_null, :no_null_byte, :types, :unique, :max_length, :max_value, :min_value].each{|v| skip_auto_validations(v)}
  when :not_null
    auto_validate_not_null_columns.clear
    auto_validate_explicit_not_null_columns.clear
  when :types
    @auto_validate_types = false
  else
    public_send("auto_validate_#{type}_columns").clear
  end
end