module RatatuiRuby::Widgets::CoerceableWidget
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
class Table < Data.define(:rows, :widths, ...) include CoerceableWidget end # In WidgetFactories: def table(first = nil, **kwargs) Widgets::Table.coerce_args(first, kwargs) end
Public Class Methods
Source
# 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
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.