Module: DesignSystem::Registry
- Defined in:
- lib/design_system/registry.rb
Overview
This provides a design system factory
Class Attribute Summary collapse
-
.design_systems ⇒ Object
Returns the value of attribute design_systems.
Class Method Summary collapse
- .builder(brand, klass_name, context) ⇒ Object
-
.component(brand, name) ⇒ Object
Resolves a per-brand component class.
- .form_builder(brand) ⇒ Object
- .register(brand) ⇒ Object
- .registered?(brand) ⇒ Boolean
- .unregister(*brands) ⇒ Object
Class Attribute Details
.design_systems ⇒ Object
Returns the value of attribute design_systems.
5 6 7 |
# File 'lib/design_system/registry.rb', line 5 def design_systems @design_systems end |
Class Method Details
.builder(brand, klass_name, context) ⇒ Object
19 20 21 22 23 |
# File 'lib/design_system/registry.rb', line 19 def builder(brand, klass_name, context) klass = namespaced_builder_klass(brand, klass_name) klass.new(context) end |
.component(brand, name) ⇒ Object
Resolves a per-brand component class. The component is responsible for
rendering — call render(component(brand, :panel).new(...)) from a
helper. Coexists with builder during the gradual migration from
PORO builders to ViewComponents.
29 30 31 32 33 34 35 |
# File 'lib/design_system/registry.rb', line 29 def component(brand, name) raise ArgumentError, "Unknown brand: #{brand}" unless registered?(brand) klass_name = "DesignSystem::#{brand.camelize}::#{name.to_s.camelize}Component" klass_name.safe_constantize || raise(ArgumentError, "Unknown component: #{name} for brand #{brand}") end |
.form_builder(brand) ⇒ Object
37 38 39 40 41 |
# File 'lib/design_system/registry.rb', line 37 def form_builder(brand) raise ArgumentError, "Unknown brand: #{brand}" unless registered?(brand) "DesignSystem::#{brand.camelcase}::FormBuilder".constantize end |
.register(brand) ⇒ Object
7 8 9 10 11 |
# File 'lib/design_system/registry.rb', line 7 def register(brand) @design_systems ||= [] @design_systems << brand end |
.registered?(brand) ⇒ Boolean
43 44 45 |
# File 'lib/design_system/registry.rb', line 43 def registered?(brand) Array(design_systems).include?(brand) end |
.unregister(*brands) ⇒ Object
13 14 15 16 17 |
# File 'lib/design_system/registry.rb', line 13 def unregister(*brands) brands.each do |brand| @design_systems.delete(brand) end end |