module Sequel::Plugins::AutoValidationsConstraintValidationsPresenceMessage

  1. lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb

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

Methods

Public Class

  1. apply
  2. configure

Public Class methods

apply(model)
[show source]
   # File lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb
30 def self.apply(model)
31   model.plugin :auto_validations
32   model.plugin :constraint_validations
33 end
configure(model, opts=OPTS)
[show source]
   # File lib/sequel/plugins/auto_validations_constraint_validations_presence_message.rb
35 def self.configure(model, opts=OPTS)
36   model.send(:_adjust_auto_validations_constraint_validations_presence_message)
37 end