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.



143
144
145
# File 'lib/sequel/plugins/auto_validations.rb', line 143

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.



147
148
149
# File 'lib/sequel/plugins/auto_validations.rb', line 147

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.



151
152
153
# File 'lib/sequel/plugins/auto_validations.rb', line 151

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.



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

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



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

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



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

def auto_validate_not_null_columns
  @auto_validate_not_null_columns
end

#auto_validate_optionsObject (readonly)

Inherited options



161
162
163
# File 'lib/sequel/plugins/auto_validations.rb', line 161

def auto_validate_options
  @auto_validate_options
end

#auto_validate_unique_columnsObject (readonly)

The columns or sets of columns with automatic unique validations



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

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)


177
178
179
# File 'lib/sequel/plugins/auto_validations.rb', line 177

def auto_validate_presence?
  @auto_validate_presence
end

#auto_validate_types?Boolean

Whether to automatically validate schema types for all columns

Returns:

  • (Boolean)


182
183
184
# File 'lib/sequel/plugins/auto_validations.rb', line 182

def auto_validate_types?
  @auto_validate_types
end

#freezeObject

Freeze auto_validation settings when freezing model class.



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

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.



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

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