Module: DevSuite::Utils::Construct::Component::Manager::ClassMethods
- Defined in:
- lib/dev_suite/utils/construct/component/manager.rb
Instance Method Summary collapse
-
#build_component(component_key, **options, &block) ⇒ Object
Build a single component.
- #build_component_from_instance(instance) ⇒ Object
-
#build_components(component_keys) ⇒ Object
Build multiple components by filtering registered ones.
-
#component_registered?(component_key) ⇒ Boolean
Check if a component is registered.
-
#registered_components ⇒ Object
Stores a mapping of component symbols to their respective classes.
Instance Method Details
#build_component(component_key, **options, &block) ⇒ Object
Build a single component
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dev_suite/utils/construct/component/manager.rb', line 30 def build_component(component_key, **, &block) component_class = registered_components[component_key] raise ArgumentError, "Component not found for key: #{component_key}" unless component_class # Check if options are empty to avoid passing unnecessary keyword arguments in Ruby 2.6 if .empty? component_class.new(&block) else component_class.new(**, &block) end end |
#build_component_from_instance(instance) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dev_suite/utils/construct/component/manager.rb', line 49 def build_component_from_instance(instance) component_class = registered_components.find do |klass, _| instance.is_a?(klass) end raise ArgumentError, "Component not found for instance: #{instance.class}" unless component_class component_class.last.new end |
#build_components(component_keys) ⇒ Object
Build multiple components by filtering registered ones
44 45 46 47 |
# File 'lib/dev_suite/utils/construct/component/manager.rb', line 44 def build_components(component_keys) component_keys.select { |key| component_registered?(key) } .map { |key| build_component(key) } end |
#component_registered?(component_key) ⇒ Boolean
Check if a component is registered
21 22 23 24 25 26 27 |
# File 'lib/dev_suite/utils/construct/component/manager.rb', line 21 def component_registered?(component_key) unless registered_components.key?(component_key) Utils::Logger.log("Component not found for key: #{component_key}", level: :warn, emoji: :warning) return false end true end |
#registered_components ⇒ Object
Stores a mapping of component symbols to their respective classes
16 17 18 |
# File 'lib/dev_suite/utils/construct/component/manager.rb', line 16 def registered_components @registered_components ||= {} end |