Class: Journeybook::ComponentRegistry
- Inherits:
-
Object
- Object
- Journeybook::ComponentRegistry
- Includes:
- Enumerable
- Defined in:
- lib/journeybook/component_registry.rb
Defined Under Namespace
Classes: Component
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #fetch(name) ⇒ Object
- #for_site(site) ⇒ Object
-
#initialize ⇒ ComponentRegistry
constructor
A new instance of ComponentRegistry.
- #register(name, component_class, **metadata) ⇒ Component
- #registered(name) ⇒ Component?
- #schema ⇒ Array<Hash>
Constructor Details
#initialize ⇒ ComponentRegistry
Returns a new instance of ComponentRegistry.
74 75 76 |
# File 'lib/journeybook/component_registry.rb', line 74 def initialize @components = {} end |
Instance Method Details
#each(&block) ⇒ Object
121 122 123 |
# File 'lib/journeybook/component_registry.rb', line 121 def each(&block) @components.values.each(&block) end |
#fetch(name) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/journeybook/component_registry.rb', line 90 def fetch(name) registered = @components.fetch(normalize_name(name)) do raise UnknownComponentError, "Unknown Journeybook component: #{name}" end registered.component_class end |
#for_site(site) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/journeybook/component_registry.rb', line 109 def for_site(site) return self unless site filtered = self.class.new @components.values.each do |component| next unless component_available_for_site?(component, site) filtered.register(component.name, component.component_class, **component.) end filtered end |
#register(name, component_class, **metadata) ⇒ Component
82 83 84 85 |
# File 'lib/journeybook/component_registry.rb', line 82 def register(name, component_class, **) normalized_name = normalize_name(name) @components[normalized_name] = Component.new(normalized_name, component_class, ) end |
#registered(name) ⇒ Component?
100 101 102 |
# File 'lib/journeybook/component_registry.rb', line 100 def registered(name) @components[normalize_name(name)] end |
#schema ⇒ Array<Hash>
105 106 107 |
# File 'lib/journeybook/component_registry.rb', line 105 def schema @components.values.map(&:schema) end |