class Sequel::ConstraintValidations::Generator

  1. lib/sequel/extensions/constraint_validations.rb
Superclass: Object

This is the DSL class used for the validate block inside create_table and alter_table.

Methods

Public Class

  1. new

Public Instance

  1. drop
  2. operator
  3. process

Public Class methods

new(generator)

Store the schema generator that encloses this validates block.

[show source]
    # File lib/sequel/extensions/constraint_validations.rb
158 def initialize(generator)
159   @generator = generator
160 end

Public Instance methods

drop(constraint)

Given the name of a constraint, drop that constraint from the database, and remove the related validation metadata.

[show source]
    # File lib/sequel/extensions/constraint_validations.rb
199 def drop(constraint)
200   @generator.validation({:type=>:drop, :name=>constraint})
201 end
operator(op, arg, columns, opts=OPTS)

Create operator validation. The op should be either :>, +:>=+, :<, or +:<=+, and the arg should be either a string or an integer.

[show source]
    # File lib/sequel/extensions/constraint_validations.rb
182 def operator(op, arg, columns, opts=OPTS)
183   raise Error, "invalid operator (#{op}) used when creating operator validation" unless suffix = OPERATORS[op]
184 
185   prefix = case arg
186   when String
187     "str"
188   when Integer
189     "int"
190   else
191     raise Error, "invalid argument (#{arg.inspect}) used when creating operator validation"
192   end
193 
194   @generator.validation({:type=>:"#{prefix}_#{suffix}", :columns=>Array(columns), :arg=>arg}.merge!(opts))
195 end
process(&block)

Alias of instance_exec for a nicer API.

[show source]
    # File lib/sequel/extensions/constraint_validations.rb
204 def process(&block)
205   instance_exec(&block)
206 end