Class: TableStructure::Schema::Definition::Validator
- Inherits:
-
Object
- Object
- TableStructure::Schema::Definition::Validator
- Defined in:
- lib/table_structure/schema/definition/validator.rb
Constant Summary collapse
- DEFAULT_SIZE =
1
Instance Method Summary collapse
-
#initialize(index, options) ⇒ Validator
constructor
A new instance of Validator.
- #validate(name:, key:, size:) ⇒ Object
Constructor Details
#initialize(index, options) ⇒ Validator
Returns a new instance of Validator.
9 10 11 12 |
# File 'lib/table_structure/schema/definition/validator.rb', line 9 def initialize(index, ) @index = index @options = end |
Instance Method Details
#validate(name:, key:, size:) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/table_structure/schema/definition/validator.rb', line 14 def validate(name:, key:, size:, **) if key.respond_to?(:call) raise Error.new('"key" must not be lambda.', @index) end if !key && name.respond_to?(:call) && !size raise Error.new('"size" must be specified, because column size cannot be determined.', @index) end if size && size < DEFAULT_SIZE raise Error.new('"size" must be positive.', @index) end if @options[:result_type] == :hash && !key raise Error.new('"key" must be specified when "result_type: :hash" is specified.', @index) end true end |