Module: SkinnyControllers::Lookup::Namespace
- Defined in:
- lib/skinny_controllers/lookup/namespace.rb
Class Method Summary collapse
-
.create_namespace(desired_namespace) ⇒ Object
iterate through the namespaces until one doesn’t exist, and create the rest.
Class Method Details
.create_namespace(desired_namespace) ⇒ Object
iterate through the namespaces until one doesn’t exist, and create the rest
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/skinny_controllers/lookup/namespace.rb', line 8 def create_namespace(desired_namespace) if klass = desired_namespace.safe_constantize return klass end namespaces = desired_namespace.split('::') existing = [] previous = Object namespaces.each do |namespace| current = (existing + [namespace]).join('::') begin # binding.pry Object.const_get(current) rescue NameError SkinnyControllers.logger.warn("Module #{namespace} not found, creating...") previous.const_set(namespace, Module.new) end existing << namespace previous = current.safe_constantize end SkinnyControllers.logger.warn("Namespace is nil. Attempted: '#{desired_namespace}'") unless previous previous end |