Module: TypeCollection::ClassMethods
- Defined in:
- lib/typecollection/class_methods.rb
Overview
Extended by TypeCollections to provide class level functionality (almost all functionality is class level as of the current design)
Instance Method Summary collapse
-
#__tc_members ⇒ Object
Contains the Members mapped by type.
-
#__tc_register_member(child) ⇒ Object
Registers a member.
-
#inherited(child) ⇒ Object
Overrides the default behavior when being extended by a child class.
Instance Method Details
#__tc_members ⇒ Object
Contains the Members mapped by type
15 |
# File 'lib/typecollection/class_methods.rb', line 15 def __tc_members(); @_members ||= { }; end |
#__tc_register_member(child) ⇒ Object
Registers a member
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/typecollection/class_methods.rb', line 18 def __tc_register_member(child) type = child.inferred_type() if (type.nil?) cname = child.name.split("::").last pname = self.name.split("::").last error = "Invalid name: '#{cname}'! Child class names must end with '#{pname}'." raise TypeCollection::InvalidChildType.new(error) end __tc_members()[type] = child end |
#inherited(child) ⇒ Object
Overrides the default behavior when being extended by a child class. It ensures the child is mapped for future retrieval and checks the subclass name to ensure it is a valid one
32 33 34 35 36 37 |
# File 'lib/typecollection/class_methods.rb', line 32 def inherited(child) super if (defined?(super)) unless child.name.nil? __tc_collection_root.__tc_register_member(child) end end |