Module: DBViewCTI::Model::CTI::Hierarchy::ClassMethods
- Defined in:
- lib/db_view_cti/model/cti/hierarchy.rb
Instance Attribute Summary collapse
-
#cti_ascendants ⇒ Object
Returns the value of attribute cti_ascendants.
-
#cti_association_proxies ⇒ Object
Returns the value of attribute cti_association_proxies.
-
#cti_descendants ⇒ Object
Returns the value of attribute cti_descendants.
Instance Method Summary collapse
-
#cti_all_descendants ⇒ Object
returns a list of all descendants.
- #cti_base_class? ⇒ Boolean
- #cti_derived_class? ⇒ Boolean
-
#cti_register_ascendants(ascendants) ⇒ Object
registers the ascendants of the current class.
-
#cti_register_descendants(class_name, descendants = {}) ⇒ Object
registers a derived class and its descendants in the current class class_name: name of derived class (the one calling cti_register_descendants on this class) descendants: the descendants of the derived class.
Instance Attribute Details
#cti_ascendants ⇒ Object
Returns the value of attribute cti_ascendants.
17 18 19 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 17 def cti_ascendants @cti_ascendants end |
#cti_association_proxies ⇒ Object
Returns the value of attribute cti_association_proxies.
17 18 19 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 17 def cti_association_proxies @cti_association_proxies end |
#cti_descendants ⇒ Object
Returns the value of attribute cti_descendants.
17 18 19 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 17 def cti_descendants @cti_descendants end |
Instance Method Details
#cti_all_descendants ⇒ Object
returns a list of all descendants
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 42 def cti_all_descendants result = [] block = Proc.new do |klass, descendants| result << klass descendants.each(&block) end @cti_descendants ||= {} @cti_descendants.each(&block) result end |
#cti_base_class? ⇒ Boolean
9 10 11 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 9 def cti_base_class? !!@cti_base_class end |
#cti_derived_class? ⇒ Boolean
13 14 15 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 13 def cti_derived_class? !!@cti_derived_class end |
#cti_register_ascendants(ascendants) ⇒ Object
registers the ascendants of the current class. Called on this class by the parent class. ascendants: array of ascendants. The first element is the highest level class, derived classes follow, the last element is the parent of this class.
37 38 39 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 37 def cti_register_ascendants(ascendants) @cti_ascendants = ascendants end |
#cti_register_descendants(class_name, descendants = {}) ⇒ Object
registers a derived class and its descendants in the current class class_name: name of derived class (the one calling cti_register_descendants on this class) descendants: the descendants of the derived class
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/db_view_cti/model/cti/hierarchy.rb', line 22 def cti_register_descendants(class_name, descendants = {}) @cti_descendants ||= {} @cti_descendants[class_name] = descendants if cti_derived_class? # call up the chain. This will also cause the register_ascendants callbacks self.superclass.cti_register_descendants(self.name, @cti_descendants) end # call back to calling class @cti_ascendants ||= [] class_name.constantize.cti_register_ascendants(@cti_ascendants + [ self.name ]) end |