Class: Sequel::ConstraintValidations::Generator
- Defined in:
- lib/sequel/extensions/constraint_validations.rb
Overview
This is the DSL class used for the validate block inside create_table and alter_table.
Instance Method Summary collapse
- 
  
    
      #drop(constraint)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Given the name of a constraint, drop that constraint from the database, and remove the related validation metadata. 
- 
  
    
      #initialize(generator)  ⇒ Generator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Store the schema generator that encloses this validates block. 
- 
  
    
      #operator(op, arg, columns, opts = OPTS)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Create operator validation. 
- 
  
    
      #process(&block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Alias of instance_exec for a nicer API. 
Constructor Details
#initialize(generator) ⇒ Generator
Store the schema generator that encloses this validates block.
| 158 159 160 | # File 'lib/sequel/extensions/constraint_validations.rb', line 158 def initialize(generator) @generator = generator end | 
Instance Method Details
#drop(constraint) ⇒ Object
Given the name of a constraint, drop that constraint from the database, and remove the related validation metadata.
| 199 200 201 | # File 'lib/sequel/extensions/constraint_validations.rb', line 199 def drop(constraint) @generator.validation({:type=>:drop, :name=>constraint}) end | 
#operator(op, arg, columns, opts = OPTS) ⇒ Object
Create operator validation.  The op should be either :>, :>=, :<, or :<=, and the arg should be either a string or an integer.
| 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | # File 'lib/sequel/extensions/constraint_validations.rb', line 182 def operator(op, arg, columns, opts=OPTS) raise Error, "invalid operator (#{op}) used when creating operator validation" unless suffix = OPERATORS[op] prefix = case arg when String "str" when Integer "int" else raise Error, "invalid argument (#{arg.inspect}) used when creating operator validation" end @generator.validation({:type=>:"#{prefix}_#{suffix}", :columns=>Array(columns), :arg=>arg}.merge!(opts)) end | 
#process(&block) ⇒ Object
Alias of instance_exec for a nicer API.
| 204 205 206 | # File 'lib/sequel/extensions/constraint_validations.rb', line 204 def process(&block) instance_exec(&block) end |