Module: Aef::NamespaceHelper::ClassMethods
- Defined in:
- lib/aef/namespace_helper.rb
Overview
This mixin module is intended to extend a single class/module object to make the helper methods only available on that specific class/module.
Instance Method Summary collapse
-
#namespace_component_names ⇒ Array<String>
Lists all namespace components’ names.
-
#namespace_components ⇒ Array<Class, Module>
Lists all namespace components.
-
#namespace_parent ⇒ Class, Module
The component in the namespace which encapsulates this class/module.
-
#namespace_parent_name ⇒ String
The name of component in the namespace which encapsulates this class/module.
-
#unprefixed_name ⇒ String
The name of the class/module itself, without any namespacing.
-
#unprefixed_namespace_component_names ⇒ Array<String>
Lists all namespace components’ unprefixed names.
Instance Method Details
#namespace_component_names ⇒ Array<String>
This will not reference the class/module objects and thus won’t trigger autoloading
Lists all namespace components’ names.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/aef/namespace_helper.rb', line 95 def namespace_component_names if self.name.nil? || self.name == '' [] else unprefixed_names = unprefixed_namespace_component_names names = [] while current_name = unprefixed_names.pop current_full_name = (unprefixed_names + [current_name]).join('::') names.unshift(current_full_name) end names end end |
#namespace_components ⇒ Array<Class, Module>
Lists all namespace components.
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/aef/namespace_helper.rb', line 120 def namespace_components components = [] unprefixed_names = unprefixed_namespace_component_names current_component = Object while current_name = unprefixed_names.shift current_component = current_component.const_get(current_name) components << current_component end components end |
#namespace_parent ⇒ Class, Module
The component in the namespace which encapsulates this class/module.
153 154 155 |
# File 'lib/aef/namespace_helper.rb', line 153 def namespace_parent namespace_components[-2] end |
#namespace_parent_name ⇒ String
This will not reference the class/module objects and thus won’t trigger autoloading
The name of component in the namespace which encapsulates this class/module.
142 143 144 |
# File 'lib/aef/namespace_helper.rb', line 142 def namespace_parent_name namespace_component_names[-2] end |
#unprefixed_name ⇒ String
The name of the class/module itself, without any namespacing.
63 64 65 |
# File 'lib/aef/namespace_helper.rb', line 63 def unprefixed_name unprefixed_namespace_component_names.last end |
#unprefixed_namespace_component_names ⇒ Array<String>
This will not reference the class/module objects and thus won’t trigger autoloading
Lists all namespace components’ unprefixed names.
77 78 79 80 81 82 83 |
# File 'lib/aef/namespace_helper.rb', line 77 def unprefixed_namespace_component_names if self.name.nil? || self.name == '' [] else self.name.split('::') end end |