Module: Sequel::Plugins::AutoValidationsConstraintValidationsPresenceMessage

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

Overview

The auto_validations_constraint_validations_presence_message plugin provides integration for the auto_validations and constraint_validations plugins in the following situation:

  • A column has a NOT NULL constraint in the database

  • A constraint validation for presence exists on the column, with a :message option to set a column-specific message, and with the :allow_nil option set to true because the CHECK constraint doesn’t need to check for NULL values as the column itself is NOT NULL

In this case, by default the validation error message on the column will use the more specific constraint validation error message if the column has a non-NULL empty value, but will use the default auto_validations message if the column has a NULL value. With this plugin, the column-specific constraint validation error message will be used in both cases.

Usage:

# Make all model subclasses use this auto_validations/constraint_validations
# integration (called before loading subclasses)
Sequel::Model.plugin :auto_validations_constraint_validations_presence_message

# Make the Album class use this auto_validations/constraint_validations integration
Album.plugin :auto_validations_constraint_validations_presence_message

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.apply(model) ⇒ Object



30
31
32
33
# File 'lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb', line 30

def self.apply(model)
  model.plugin :auto_validations
  model.plugin :constraint_validations
end

.configure(model, opts = OPTS) ⇒ Object



35
36
37
# File 'lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb', line 35

def self.configure(model, opts=OPTS)
  model.send(:_adjust_auto_validations_constraint_validations_presence_message)
end