Module: RubyUiScaffold::ComponentResolver
- Defined in:
- lib/ruby_ui_scaffold/component_resolver.rb
Overview
Resolves which ruby_ui components a scaffold references, given its
attributes and options. Only DIRECT references are listed — the
ruby_ui:component NAME generator resolves transitive dependencies
itself (e.g. date_picker pulls calendar + popover + input;
data_table pulls table, checkbox, native_select, pagination,
dropdown_menu, input, button). See ruby_ui's dependencies.yml.
Constant Summary collapse
- BASE =
Components every generated scaffold uses, regardless of columns/flags. The install generator pre-installs these so a bare
:installleaves the ground ready; the scaffold then adds the column/flag-specific ones.index → table, link, button, dropdown_menu, alert_dialog show → card, typography (Text), link, button form → form (FormField*), input, button %w[ table link button card typography dropdown_menu alert_dialog form input ].freeze
Class Method Summary collapse
-
.call(attributes:, datatable: false) ⇒ Object
The full set of ruby_ui component generator names a scaffold with these attributes/options references — BASE plus the column/flag conditionals.
-
.components_for_attribute(attribute) ⇒ Object
Conditional components a single attribute pulls in: boolean → Badge (index/show) + Checkbox (form) text → Textarea (form) reference → Combobox + Select (form) — polymorphic falls back to a plain number Input, so it adds nothing date → DatePicker (form) Everything else (string/integer/float/decimal/time/datetime/password/ attachment/polymorphic reference) maps to the base
input. - .reference?(attribute) ⇒ Boolean
Class Method Details
.call(attributes:, datatable: false) ⇒ Object
The full set of ruby_ui component generator names a scaffold with these attributes/options references — BASE plus the column/flag conditionals. Returns a sorted, de-duplicated array.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ruby_ui_scaffold/component_resolver.rb', line 39 def call(attributes:, datatable: false) components = BASE.dup components << "data_table" if datatable attributes.each do |attribute| components.concat(components_for_attribute(attribute)) end components.uniq.sort end |
.components_for_attribute(attribute) ⇒ Object
Conditional components a single attribute pulls in:
boolean → Badge (index/show) + Checkbox (form)
text → Textarea (form)
reference → Combobox + Select (form) — polymorphic falls back to a
plain number Input, so it adds nothing
date → DatePicker (form)
Everything else (string/integer/float/decimal/time/datetime/password/
attachment/polymorphic reference) maps to the base input.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_ui_scaffold/component_resolver.rb', line 58 def components_for_attribute(attribute) return %w[combobox select] if reference?(attribute) case attribute.type when :boolean then %w[badge checkbox] when :text then %w[textarea] when :date then %w[date_picker] else [] end end |
.reference?(attribute) ⇒ Boolean
69 70 71 72 |
# File 'lib/ruby_ui_scaffold/component_resolver.rb', line 69 def reference?(attribute) attribute.respond_to?(:reference?) && attribute.reference? && !(attribute.respond_to?(:polymorphic?) && attribute.polymorphic?) end |