Class: Filterameter::Registries::SubRegistry
- Inherits:
-
Object
- Object
- Filterameter::Registries::SubRegistry
- Defined in:
- lib/filterameter/registries/sub_registry.rb
Overview
# SubRegistry
Class SubRegistry provides add and fetch methods as well as the initialization for sub-registries.
Subclasses must implement build_declaration.
Direct Known Subclasses
Instance Method Summary collapse
- #add(parameter_name, options) ⇒ Object
- #fetch(parameter_name) ⇒ Object
-
#initialize(factory) ⇒ SubRegistry
constructor
A new instance of SubRegistry.
- #parameter_names ⇒ Object
Constructor Details
#initialize(factory) ⇒ SubRegistry
Returns a new instance of SubRegistry.
11 12 13 14 15 |
# File 'lib/filterameter/registries/sub_registry.rb', line 11 def initialize(factory) @factory = factory @declarations = {} @registry = {} end |
Instance Method Details
#add(parameter_name, options) ⇒ Object
17 18 19 20 |
# File 'lib/filterameter/registries/sub_registry.rb', line 17 def add(parameter_name, ) name = parameter_name.to_s @declarations[name] = build_declaration(name, ) end |
#fetch(parameter_name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/filterameter/registries/sub_registry.rb', line 22 def fetch(parameter_name) name = parameter_name.to_s @registry.fetch(name) do raise Filterameter::Exceptions::UndeclaredParameterError, name unless @declarations.keys.include?(name) @registry[name] = @factory.build(@declarations[name]) end end |
#parameter_names ⇒ Object
31 32 33 |
# File 'lib/filterameter/registries/sub_registry.rb', line 31 def parameter_names @declarations.keys end |