Module: TTY::Table::Validatable Private
- Included in:
- TTY::Table, Renderer::Basic
- Defined in:
- lib/tty/table/validatable.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Mixin to provide validation for TTY::Table.
Include this mixin to add validation for options.
Instance Method Summary collapse
-
#assert_row_size(row, rows) ⇒ nil
private
Check if table row is the correct size.
-
#assert_row_sizes(rows) ⇒ nil
private
Check if table rows are the equal size.
-
#assert_table_type(value) ⇒ Table
private
Check if table type is provided.
-
#validate_options!(options) ⇒ Object
private
Check if options are of required type.
Instance Method Details
#assert_row_size(row, rows) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if table row is the correct size
38 39 40 41 42 43 44 |
# File 'lib/tty/table/validatable.rb', line 38 def assert_row_size(row, rows) return if rows.empty? size = rows.last.size return if row.size == size raise TTY::Table::DimensionMismatchError, "row size differs (#{row.size} should be #{size})" end |
#assert_row_sizes(rows) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if table rows are the equal size
21 22 23 24 25 26 27 28 |
# File 'lib/tty/table/validatable.rb', line 21 def assert_row_sizes(rows) size = (rows[0] || []).size rows.each do |row| next if row.size == size raise TTY::Table::DimensionMismatchError, "row size differs (#{row.size} should be #{size})" end end |
#assert_table_type(value) ⇒ Table
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if table type is provided
53 54 55 56 57 |
# File 'lib/tty/table/validatable.rb', line 53 def assert_table_type(value) return value if value.is_a?(TTY::Table) raise ArgumentRequired, "Expected TTY::Table instance, got #{value.inspect}" end |
#validate_options!(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if options are of required type
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tty/table/validatable.rb', line 68 def () header = [:header] rows = [:rows] if header && (!header.is_a?(Array) || header.empty?) raise InvalidArgument, ":header must be a non-empty array" end if rows && !(rows.is_a?(Array) || rows.is_a?(Hash)) raise InvalidArgument, ":rows must be a non-empty array or hash" end end |