Class: RVGP::Application::DescendantRegistry::ClassRegistry
- Inherits:
-
Object
- Object
- RVGP::Application::DescendantRegistry::ClassRegistry
- Includes:
- Enumerable
- Defined in:
- lib/rvgp/application/descendant_registry.rb
Overview
This basic class resembles an array, and is used to house a regsitry of children classes. Typically, this class is instantiated inside of RVGP, at the time a child inherits from a parent.
Instance Attribute Summary collapse
-
#classes ⇒ Array<Object>
readonly
The undecorated classes that are contained in this object.
Instance Method Summary collapse
-
#add(klass) ⇒ void
Add the provided object to the #classes collection.
-
#each {|obj| ... } ⇒ void
Call the provided block, for each element of the registry.
-
#initialize(opts = {}) ⇒ ClassRegistry
constructor
Declare the registry, and initialize with the relevant options.
-
#method_missing(name) ⇒ Object
In the case that a method is called on this registry, that isn’t explicitly defined, this method checks the accessors provided in #initialize to see if there’s a matching block, indexing to the name of the missing method.
-
#names ⇒ Array<String>
The names of all the classes that are defined in this registry.
Constructor Details
#initialize(opts = {}) ⇒ ClassRegistry
Declare the registry, and initialize with the relevant options
31 32 33 34 |
# File 'lib/rvgp/application/descendant_registry.rb', line 31 def initialize(opts = {}) @classes = [] @accessors = opts[:accessors] || {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
In the case that a method is called on this registry, that isn’t explicitly defined, this method checks the accessors provided in #initialize to see if there’s a matching block, indexing to the name of the missing method. And calls that.
65 66 67 |
# File 'lib/rvgp/application/descendant_registry.rb', line 65 def method_missing(name) @accessors.key?(name) ? @accessors[name].call(self) : super(name) end |
Instance Attribute Details
#classes ⇒ Array<Object> (readonly)
The undecorated classes that are contained in this object
23 24 25 |
# File 'lib/rvgp/application/descendant_registry.rb', line 23 def classes @classes end |
Instance Method Details
#add(klass) ⇒ void
This method returns an undefined value.
Add the provided object to the #classes collection
46 47 48 |
# File 'lib/rvgp/application/descendant_registry.rb', line 46 def add(klass) @classes << klass end |
#each {|obj| ... } ⇒ void
This method returns an undefined value.
Call the provided block, for each element of the registry
39 40 41 |
# File 'lib/rvgp/application/descendant_registry.rb', line 39 def each(&block) classes.each(&block) end |
#names ⇒ Array<String>
The names of all the classes that are defined in this registry
52 53 54 |
# File 'lib/rvgp/application/descendant_registry.rb', line 52 def names classes.collect(&:name) end |