vendor/plugins/enum-column/lib/enum/validations.rb
# Automatically validates the column against the schema definition
# for nullability, format, and enumerations. Handles integers, floats,
# enumerations, and string limits.
#
# Usage: validates_columns :severity, :name
Automatically validates the column against the schema definition
for nullability, format, and enumerations. Handles integers, floats,
enumerations, and string limits.


Automatically validates the column against the schema definition for nullability format and enumerations . Handles integers floats enumerations and string limits .
def validates_columns(*column_names)
        cols = columns_hash
        column_names.each do |name|
          col = cols[name.to_s]
          raise ArgumentError, "Cannot find column #{name}" unless col
          validates_presence_of(name) if !col.null
          case col.type
          when :enum
            validates_inclusion_of name, :in => col.values, :allow_nil => true
          when :integer, :float
            validates_numericality_of name, :allow_nil => true
          when :string
            if col.limit
              validates_length_of name, :maximum => col.limit, :allow_nil => true
            end
          end
        end
      end
def validates_columns ( * column_names ) cols = columns_hash column_names . each do | name | col = cols [ name . to_s ] raise ArgumentError , "Cannot find column #{name}" unless col validates_presence_of ( name ) if ! col . null case col . type when :enum validates_inclusion_of name , :in => col . values , :allow_nil => true when :integer , :float validates_numericality_of name , :allow_nil => true when :string if col . limit validates_length_of name , :maximum => col . limit , :allow_nil => true end end end end
Automatically validates the column against the schema definition
for nullability, format, and enumerations.
Automatically validates the column against the schema definition for nullability format and enumerations .
# test for nullability # Test various known types.
column_names
<not_specific>