Class: Filterameter::Registries::SubRegistry

Inherits:
Object
  • Object
show all
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

FilterRegistry, SortRegistry

Instance Method Summary collapse

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, options)
  name = parameter_name.to_s
  @declarations[name] = build_declaration(name, options)
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_namesObject



31
32
33
# File 'lib/filterameter/registries/sub_registry.rb', line 31

def parameter_names
  @declarations.keys
end