Class: Tailmix::Registry
- Inherits:
-
Object
- Object
- Tailmix::Registry
- Includes:
- Singleton
- Defined in:
- lib/tailmix/registry.rb
Overview
A per-request registry to store unique component classes rendered during a request-response cycle.
Instance Method Summary collapse
-
#clear! ⇒ Object
Clears the registry.
-
#definitions ⇒ Hash
Gathers definitions from all registered classes.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#register(component_class) ⇒ Object
Registers a component class.
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
11 12 13 |
# File 'lib/tailmix/registry.rb', line 11 def initialize @component_classes = Set.new end |
Instance Method Details
#clear! ⇒ Object
Clears the registry. Must be called after each request.
33 34 35 |
# File 'lib/tailmix/registry.rb', line 33 def clear! @component_classes.clear end |
#definitions ⇒ Hash
Gathers definitions from all registered classes.
23 24 25 26 27 28 29 30 |
# File 'lib/tailmix/registry.rb', line 23 def definitions @component_classes.each_with_object({}) do |klass, hash| component_name = klass.name if component_name && klass.respond_to?(:tailmix_definition) hash[component_name] = klass.tailmix_definition.to_h end end end |
#register(component_class) ⇒ Object
Registers a component class.
17 18 19 |
# File 'lib/tailmix/registry.rb', line 17 def register(component_class) @component_classes.add(component_class) end |