Class: Toys::ModuleLookup

Inherits:
Object
  • Object
show all
Defined in:
core-docs/toys/module_lookup.rb

Overview

A helper module that provides methods to do module lookups. This is used to obtain named helpers, middleware, and templates from the respective modules.

Defined in the toys-core gem

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ ModuleLookup

Create an empty ModuleLookup



47
48
49
# File 'core-docs/toys/module_lookup.rb', line 47

def initialize
  # Source available in the toys-core gem
end

Class Method Details

.path_to_module(path) ⇒ Module

Given a require path, return the module expected to be defined.

Parameters:

  • path (String) —

    File path, delimited by forward slash

Returns:

  • (Module) —

    The module loaded from that path



39
40
41
# File 'core-docs/toys/module_lookup.rb', line 39

def path_to_module(path)
  # Source available in the toys-core gem
end

.to_module_name(str) ⇒ Symbol

Convert the given string to a module name. Specifically, converts to UpperCamelCase, and then to a symbol.

Parameters:

  • str (String, Symbol) —

    String to convert.

Returns:

  • (Symbol) —

    Converted name



29
30
31
# File 'core-docs/toys/module_lookup.rb', line 29

def to_module_name(str)
  # Source available in the toys-core gem
end

.to_path_name(str) ⇒ String

Convert the given string to a path element. Specifically, converts to lower_snake_case.

Parameters:

  • str (String, Symbol) —

    String to convert.

Returns:

  • (String) —

    Converted string



18
19
20
# File 'core-docs/toys/module_lookup.rb', line 18

def to_path_name(str)
  # Source available in the toys-core gem
end

Instance Method Details

#add_path(path_base, module_base: nil, high_priority: false) ⇒ self

Add a lookup path for modules.

Parameters:

  • path_base (String) —

    The base require path

  • module_base (Module) (defaults to: nil) —

    The base module, or nil (the default) to infer a default from the path base.

  • high_priority (boolean) (defaults to: false) —

    If true, add to the head of the lookup path, otherwise add to the end.

Returns:

  • (self)


61
62
63
# File 'core-docs/toys/module_lookup.rb', line 61

def add_path(path_base, module_base: nil, high_priority: false)
  # Source available in the toys-core gem
end

#lookup(name) ⇒ Module

Obtain a named module. Returns nil if the name is not present.

Parameters:

  • name (String, Symbol) —

    The name of the module to return.

Returns:

  • (Module) —

    The specified module



71
72
73
# File 'core-docs/toys/module_lookup.rb', line 71

def lookup(name)
  # Source available in the toys-core gem
end