Class: ConfigBuilder::ClassRegistry Private
- Inherits:
-
Object
- Object
- ConfigBuilder::ClassRegistry
- Defined in:
- lib/config_builder/class_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This defines a registry for classes, and behaves as a factory for registered classes.
Defined Under Namespace
Classes: DuplicateEntry, UnknownEntry
Instance Method Summary collapse
-
#generate(hash) ⇒ Object
private
Generate a class instance with the given hash.
-
#initialize(name) ⇒ ClassRegistry
constructor
private
A new instance of ClassRegistry.
- #inspect ⇒ Object private
-
#register(identifier, klass) ⇒ void
private
Register a class with a given identifier.
-
#retrieve(identifier) ⇒ Class
private
Retrieve a class associated with the specified identifier.
Constructor Details
#initialize(name) ⇒ ClassRegistry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ClassRegistry.
18 19 20 21 |
# File 'lib/config_builder/class_registry.rb', line 18 def initialize(name) @name = name @klasses = {} end |
Instance Method Details
#generate(hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a class instance with the given hash
59 60 61 62 63 64 65 66 |
# File 'lib/config_builder/class_registry.rb', line 59 def generate(hash) config = hash.dup identifier = config.delete('type') klass = retrieve(identifier) klass.new_from_hash(hash) end |
#inspect ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/config_builder/class_registry.rb', line 68 def inspect "<#{self.class}: (#{@name}) keys: #{@klasses.keys.inspect}>" end |
#register(identifier, klass) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Register a class with a given identifier
29 30 31 32 33 34 35 36 |
# File 'lib/config_builder/class_registry.rb', line 29 def register(identifier, klass) if @klasses[identifier] raise DuplicateEntry, :registry => @name, :identifier => identifier.inspect else @klasses[identifier] = klass end end |
#retrieve(identifier) ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Retrieve a class associated with the specified identifier
43 44 45 46 47 48 49 50 51 |
# File 'lib/config_builder/class_registry.rb', line 43 def retrieve(identifier) if (klass = @klasses[identifier]) klass else raise UnknownEntry, :registry => @name, :identifier => identifier.inspect, :identifiers => @klasses.keys end end |