Method: Jinx::Importer#module_for_name

Defined in:
lib/jinx/importer.rb

#module_for_name(name) ⇒ Module

Returns the corresponding module.

Parameters:

  • the (String)

    module name to resolve in the context of this module

Returns:

  • (Module)

    the corresponding module

Raises:

  • (NameError)

    if the name cannot be resolved



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jinx/importer.rb', line 89

def module_for_name(name)
  begin
    # Incrementally resolve the module.
    name.split('::').inject(self) { |ctxt, mod| ctxt.const_get(mod) }
  rescue NameError
    # If the application domain module set the parent module i.v.. then continue
    # the look-up in that parent importer.
    raise unless @parent_importer
    mod = @parent_importer.module_for_name(name)
    if mod then
      logger.debug { "Module #{name} found in #{qp} parent module #{@parent_importer}." }
    end
    mod
  end
end