Module: RatatuiRuby::Widgets::CoerceableWidget
- Included in:
- Axis, BarChart, BarChart::Bar, BarChart::BarGroup, Block, Calendar, Canvas, Cell, Center, Chart, Clear, Cursor, Dataset, Gauge, LineGauge, List, ListItem, Overlay, Paragraph, RatatuiLogo, RatatuiMascot, Row, Scrollbar, Shape::Label, Sparkline, Table, Tabs
- Defined in:
- lib/ratatui_ruby/widgets/coerceable_widget.rb
Overview
Mixin that provides DWIM hash coercion for widget classes.
When users call ‘tui.table(hash)` instead of `tui.table(**hash)`, Ruby’s ‘…` forwarding passes the Hash as a positional argument, causing cryptic TypeErrors at the Rust FFI boundary.
This mixin provides a ‘coerce_args` class method that detects this pattern and automatically splats the hash into keyword arguments.
Behavior
-
**Production mode**: Unknown keys are silently ignored
-
**Debug mode (RR_DEBUG=1)**: Raises ArgumentError to catch typos early
Usage
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
class Table < Data.define(:rows, :widths, ...)
include CoerceableWidget
end
# In WidgetFactories:
def table(first = nil, **kwargs)
Widgets::Table.coerce_args(first, kwargs)
end
– SPDX-SnippetEnd ++
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
Hook called when this module is included in a widget class.
Class Method Details
.included(base) ⇒ Object
Hook called when this module is included in a widget class.
Extends the class with ClassMethods and defines KNOWN_KEYS constant from the Data.define members for validation.
- base
-
The class including this module.
50 51 52 53 |
# File 'lib/ratatui_ruby/widgets/coerceable_widget.rb', line 50 def self.included(base) base.extend(ClassMethods) base.const_set(:KNOWN_KEYS, base.members.freeze) unless base.const_defined?(:KNOWN_KEYS) end |