class TableStructure::Schema::Definition::Columns::Validator

Constants

DEFAULT_SIZE

Public Class Methods

new(name, index) click to toggle source
# File lib/table_structure/schema/definition/columns/validator.rb, line 10
def initialize(name, index)
  @name = name
  @index = index
end

Public Instance Methods

validate(name:, key:, size:, **) click to toggle source
# File lib/table_structure/schema/definition/columns/validator.rb, line 15
def validate(name:, key:, size:, **)
  raise Error.new('"key" must not be callable.', @name, @index) if key.respond_to?(:call)
  if !key && name.respond_to?(:call) && !size
    raise Error.new('"size" must be defined, because column size cannot be determined.', @name, @index)
  end
  raise Error.new('"size" must be positive.', @name, @index) if size && size < DEFAULT_SIZE
  if key && size && [key].flatten.size < size
    raise Error.new('"key" size must not be less than specified "size".', @name, @index)
  end

  true
end