Class: Toys::Loader
- Inherits:
-
Object
- Object
- Toys::Loader
- Defined in:
- core-docs/toys/loader.rb,
core-docs/toys/loader/load_state.rb,
core-docs/toys/loader/tool_registry.rb
Overview
The Loader service loads tools from tool sources, and finds the appropriate tool given a set of command line arguments.
Defined in the toys-core gem
Constant Summary collapse
- FALLBACK_ROOT_PRIORITY =
The priority of the always-present fallback root tool. This is the priority of the root tool that will be returned from lookups if no sources have been added. If any source is added, it will have a higher priority than this, and its tools will supersede this fallback.
-999_999_999
Instance Attribute Summary collapse
-
#tool_name_splitter ⇒ Toys::ToolNameSplitter
readonly
The splitter that interprets delimiters in the tool names handled by this loader.
Instance Method Summary collapse
-
#has_subtools?(words) ⇒ boolean
Returns true if the given path has at least one subtool, even if they are hidden or non-runnable.
-
#initialize(source_list, tool_name_splitter: nil, middleware_stack: [], mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil, gems_util: nil) ⇒ Loader
constructor
Create a Loader.
-
#list_subtools(words, recursive: false, include_hidden: false, include_namespaces: false, include_non_runnable: false) ⇒ Array<Toys::ToolDefinition>
Returns a list of subtools for the given path, loading from their sources and ensuring they are finished.
-
#lookup(args) ⇒ Array(Toys::ToolDefinition,Array<String>)
Given a list of command line arguments, find the appropriate tool to handle the command, loading it from its source if necessary and ensuring it has been finished.
-
#lookup_specific(words) ⇒ Toys::ToolDefinition?
Given a tool name, looks up the specific tool, loading it from its source if necessary and ensuring it has been finished.
-
#resolve_sources ⇒ self
Ensures all root sources get resolved eagerly.
Constructor Details
#initialize(source_list, tool_name_splitter: nil, middleware_stack: [], mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil, gems_util: nil) ⇒ Loader
Create a Loader.
55 56 57 58 59 60 61 62 63 64 |
# File 'core-docs/toys/loader.rb', line 55 def initialize(source_list, tool_name_splitter: nil, middleware_stack: [], mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil, gems_util: nil) # Source available in the toys-core gem end |
Instance Attribute Details
#tool_name_splitter ⇒ Toys::ToolNameSplitter (readonly)
The splitter that interprets delimiters in the tool names handled by this loader. Use it to convert a delimited name into words.
72 73 74 |
# File 'core-docs/toys/loader.rb', line 72 def tool_name_splitter @tool_name_splitter end |
Instance Method Details
#has_subtools?(words) ⇒ boolean
Returns true if the given path has at least one subtool, even if they are hidden or non-runnable. Loads from the sources if necessary.
151 152 153 |
# File 'core-docs/toys/loader.rb', line 151 def has_subtools?(words) # Source available in the toys-core gem end |
#list_subtools(words, recursive: false, include_hidden: false, include_namespaces: false, include_non_runnable: false) ⇒ Array<Toys::ToolDefinition>
Returns a list of subtools for the given path, loading from their sources and ensuring they are finished. The list will be sorted by name.
133 134 135 136 137 138 139 |
# File 'core-docs/toys/loader.rb', line 133 def list_subtools(words, recursive: false, include_hidden: false, include_namespaces: false, include_non_runnable: false) # Source available in the toys-core gem end |
#lookup(args) ⇒ Array(Toys::ToolDefinition,Array<String>)
Given a list of command line arguments, find the appropriate tool to handle the command, loading it from its source if necessary and ensuring it has been finished. This always returns a tool. If the specific tool path is not defined and cannot be found in any source, it finds the nearest namespace that would contain that tool, up to the root tool (which always exists.)
Returns a tuple of the found tool, and the array of remaining arguments that are not part of the tool name and should be passed as tool args.
91 92 93 |
# File 'core-docs/toys/loader.rb', line 91 def lookup(args) # Source available in the toys-core gem end |
#lookup_specific(words) ⇒ Toys::ToolDefinition?
Given a tool name, looks up the specific tool, loading it from its source if necessary and ensuring it has been finished.
If there is an active tool, returns it; otherwise, returns the highest
priority tool that has been defined. If no tool has been defined with
the given name, returns nil.
110 111 112 |
# File 'core-docs/toys/loader.rb', line 110 def lookup_specific(words) # Source available in the toys-core gem end |
#resolve_sources ⇒ self
Ensures all root sources get resolved eagerly. Does not actually load any tools.
Can be called pre-emptively prior to other methods to prevent them from
raising ToolSourceError directly. (It is still possible for them
to raise ToolSourceError wrapped in a ContextualError if
a tool invokes another source via one of the load directives.)
167 168 169 |
# File 'core-docs/toys/loader.rb', line 167 def resolve_sources # Source available in the toys-core gem end |