Class: TudlaContracts::Integrations::Registry
- Inherits:
-
Object
- Object
- TudlaContracts::Integrations::Registry
- Defined in:
- lib/tudla_contracts/integrations/registry.rb
Overview
Shared class for registering and looking up integrations
Constant Summary collapse
- VALID_TYPES =
%w[time_sheet].freeze
Class Method Summary collapse
-
.all_of_type(type) ⇒ Object
Used by the Host App to look up all integrations of a specific type.
-
.available_providers ⇒ Object
Used to populate UI dropdowns.
-
.config_class_for(name) ⇒ String?
Used by the Host App to find the config class for polymorphic associations.
-
.find(name) ⇒ String
Used by the Host App to look up a specific provider.
-
.register(name, type:, provider_class:, config_class:) ⇒ Object
Method called by gems to register themselves.
-
.register_view_for_slot(slot, view_definition) ⇒ Object
Method called by gems to register view definitions for slots.
-
.registered_slots ⇒ Object
Used by the Host App to look up all registered slots.
-
.reset! ⇒ Object
Reset the registry.
-
.views_for_slot(slot) ⇒ Array<String>
Used by the Host App to look up view components for a specific slot.
Class Method Details
.all_of_type(type) ⇒ Object
Used by the Host App to look up all integrations of a specific type
69 70 71 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 69 def all_of_type(type) @integrations.select { |_, v| v[:type] == type.to_s }.values end |
.available_providers ⇒ Object
Used to populate UI dropdowns
84 85 86 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 84 def available_providers @integrations.keys end |
.config_class_for(name) ⇒ String?
Used by the Host App to find the config class for polymorphic associations
76 77 78 79 80 81 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 76 def config_class_for(name) entry = @integrations[name.to_s] return nil unless entry entry[:config_class] end |
.find(name) ⇒ String
Used by the Host App to look up a specific provider
61 62 63 64 65 66 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 61 def find(name) entry = @integrations[name.to_s] raise ArgumentError, "Unknown integration: #{name}" unless entry entry[:provider_class] end |
.register(name, type:, provider_class:, config_class:) ⇒ Object
Method called by gems to register themselves
20 21 22 23 24 25 26 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 20 def register(name, type:, provider_class:, config_class:) @integrations[name.to_s] = { type: type.to_s, provider_class: provider_class.to_s, config_class: config_class.to_s } end |
.register_view_for_slot(slot, view_definition) ⇒ Object
Method called by gems to register view definitions for slots
37 38 39 40 41 42 43 44 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 37 def register_view_for_slot(slot, view_definition) unless view_definition.class.ancestors.any? { |a| a.name&.end_with?("ViewDefinitions::Base") } raise ArgumentError, "view_definition must be an instance of a class that inherits from ViewDefinitions::Base" end @view_slots[slot.to_s] ||= [] @view_slots[slot.to_s] << view_definition end |
.registered_slots ⇒ Object
Used by the Host App to look up all registered slots
54 55 56 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 54 def registered_slots @view_slots.keys end |
.reset! ⇒ Object
Reset the registry
29 30 31 32 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 29 def reset! @integrations = {} @view_slots = {} end |
.views_for_slot(slot) ⇒ Array<String>
Used by the Host App to look up view components for a specific slot
49 50 51 |
# File 'lib/tudla_contracts/integrations/registry.rb', line 49 def views_for_slot(slot) @view_slots[slot.to_s] || [] end |