Class: Avo::UIInstance
- Inherits:
-
Object
- Object
- Avo::UIInstance
- Defined in:
- lib/avo/u_i_instance.rb
Constant Summary collapse
- MISSING_COMPONENT_CLASS =
"Avo::ComponentMissingComponent"
Class Method Summary collapse
- .clear_cache! ⇒ Object
-
.method_missing(method) ⇒ Object
Used in parent apps like this ‘ui.panel(…)` @method: string “panel” @return: (method: String) -> Component.
- .resolve_component(method) ⇒ Object
- .respond_to_missing?(method, include_private = false) ⇒ Boolean
Class Method Details
.clear_cache! ⇒ Object
37 38 39 |
# File 'lib/avo/u_i_instance.rb', line 37 def clear_cache! @cache_mutex.synchronize { @component_cache.clear } end |
.method_missing(method) ⇒ Object
Used in parent apps like this ‘ui.panel(…)` @method: string “panel” @return: (method: String) -> Component
44 45 46 47 48 49 50 51 52 |
# File 'lib/avo/u_i_instance.rb', line 44 def method_missing(method, ...) component_class = resolve_component(method) if component_class component_class.new(...) else MISSING_COMPONENT_CLASS.safe_constantize.new(component_name: method) end end |
.resolve_component(method) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/avo/u_i_instance.rb', line 13 def resolve_component(method) # Check cache first (thread-safe read) cached = @component_cache[method] return cached if cached # Cache miss - resolve and store (thread-safe write) @cache_mutex.synchronize do # Double-check after acquiring lock return @component_cache[method] if @component_cache[method] component_class = "#{method.to_s.delete_suffix("_component")}_component" full_class_name = "Avo::#{component_class.classify}" ui_full_class_name = "Avo::UI::#{component_class.classify}" resolved = if Object.const_defined?(full_class_name) full_class_name.constantize elsif Object.const_defined?(ui_full_class_name) ui_full_class_name.constantize end @component_cache[method] = resolved end end |
.respond_to_missing?(method, include_private = false) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/avo/u_i_instance.rb', line 54 def respond_to_missing?(method, include_private = false) # Since method_missing always handles any method call (either with a real component # or falling back to MISSING_COMPONENT_CLASS), respond_to? should return true true end |