Class: TableStructure::Schema::Definition::Columns::Validator
- Inherits:
-
Object
- Object
- TableStructure::Schema::Definition::Columns::Validator
- Defined in:
- lib/table_structure/schema/definition/columns/validator.rb
Constant Summary collapse
- DEFAULT_SIZE =
1
Instance Method Summary collapse
-
#initialize(name, index) ⇒ Validator
constructor
A new instance of Validator.
- #validate(name:, key:, size:) ⇒ Object
Constructor Details
#initialize(name, index) ⇒ Validator
Returns a new instance of Validator.
10 11 12 13 |
# File 'lib/table_structure/schema/definition/columns/validator.rb', line 10 def initialize(name, index) @name = name @index = index end |
Instance Method Details
#validate(name:, key:, size:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/table_structure/schema/definition/columns/validator.rb', line 15 def validate(name:, key:, size:, **) raise Error.new('"key" must not be lambda.', @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 |