Class: Toys::Loader
- Inherits:
-
Object
- Object
- Toys::Loader
- Defined in:
- core-docs/toys/loader.rb
Overview
Defined in the toys-core gem
The Loader service loads tools from configuration files, and finds the appropriate tool given a set of command line arguments.
Instance Method Summary collapse
-
#add_block(high_priority: false, source_name: nil, context_directory: nil, &block) ⇒ self
Add a configuration block to the loader.
-
#add_git(git_remote, git_path, git_commit, high_priority: false, update: false, context_directory: nil) ⇒ self
Add a configuration git source to the loader.
-
#add_path(path, high_priority: false, source_name: nil, context_directory: :parent) ⇒ self
Add a configuration file/directory to the loader.
-
#add_path_set(root_path, relative_paths, high_priority: false, context_directory: :path) ⇒ self
Add a set of configuration files/directories from a common directory to the loader.
-
#has_subtools?(words) ⇒ Boolean
Returns true if the given path has at least one subtool.
-
#initialize(index_file_name: nil, preload_dir_name: nil, preload_file_name: nil, data_dir_name: nil, lib_dir_name: nil, middleware_stack: [], extra_delimiters: "", mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil) ⇒ Loader
constructor
Create a Loader.
-
#list_subtools(words, recursive: false, include_hidden: false) ⇒ Array<Toys::ToolDefinition>
Returns a list of subtools for the given path, loading from the configuration if necessary.
-
#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 the configuration if necessary.
-
#lookup_specific(words) ⇒ Toys::ToolDefinition?
Given a tool name, looks up the specific tool, loading it from the configuration if necessary.
-
#split_path(str) ⇒ Array<String>
Splits the given path using the delimiters configured in this Loader.
Constructor Details
#initialize(index_file_name: nil, preload_dir_name: nil, preload_file_name: nil, data_dir_name: nil, lib_dir_name: nil, middleware_stack: [], extra_delimiters: "", mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil) ⇒ Loader
Create a Loader
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'core-docs/toys/loader.rb', line 42 def initialize(index_file_name: nil, preload_dir_name: nil, preload_file_name: nil, data_dir_name: nil, lib_dir_name: nil, middleware_stack: [], extra_delimiters: "", mixin_lookup: nil, middleware_lookup: nil, template_lookup: nil, git_cache: nil) # Source available in the toys-core gem end |
Instance Method Details
#add_block(high_priority: false, source_name: nil, context_directory: nil, &block) ⇒ self
Add a configuration block to the loader.
119 120 121 122 123 124 |
# File 'core-docs/toys/loader.rb', line 119 def add_block(high_priority: false, source_name: nil, context_directory: nil, &block) # Source available in the toys-core gem end |
#add_git(git_remote, git_path, git_commit, high_priority: false, update: false, context_directory: nil) ⇒ self
Add a configuration git source to the loader.
144 145 146 147 148 149 |
# File 'core-docs/toys/loader.rb', line 144 def add_git(git_remote, git_path, git_commit, high_priority: false, update: false, context_directory: nil) # Source available in the toys-core gem end |
#add_path(path, high_priority: false, source_name: nil, context_directory: :parent) ⇒ self
Add a configuration file/directory to the loader.
71 72 73 74 75 76 |
# File 'core-docs/toys/loader.rb', line 71 def add_path(path, high_priority: false, source_name: nil, context_directory: :parent) # Source available in the toys-core gem end |
#add_path_set(root_path, relative_paths, high_priority: false, context_directory: :path) ⇒ self
Add a set of configuration files/directories from a common directory to the loader. The set of paths will be added at the same priority level and will share a root.
97 98 99 100 101 |
# File 'core-docs/toys/loader.rb', line 97 def add_path_set(root_path, relative_paths, high_priority: false, context_directory: :path) # Source available in the toys-core gem end |
#has_subtools?(words) ⇒ Boolean
Returns true if the given path has at least one subtool. Loads from the configuration if necessary.
206 207 208 |
# File 'core-docs/toys/loader.rb', line 206 def has_subtools?(words) # Source available in the toys-core gem end |
#list_subtools(words, recursive: false, include_hidden: false) ⇒ Array<Toys::ToolDefinition>
Returns a list of subtools for the given path, loading from the configuration if necessary.
195 196 197 |
# File 'core-docs/toys/loader.rb', line 195 def list_subtools(words, recursive: false, include_hidden: 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 the configuration if necessary. This always returns a tool. If the specific tool path is not defined and cannot be found in any configuration, it finds the nearest namespace that would contain that tool, up to the root tool.
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.
164 165 166 |
# File 'core-docs/toys/loader.rb', line 164 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 the configuration if necessary.
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
.
180 181 182 |
# File 'core-docs/toys/loader.rb', line 180 def lookup_specific(words) # Source available in the toys-core gem end |
#split_path(str) ⇒ Array<String>
Splits the given path using the delimiters configured in this Loader. You may pass in either an array of strings, or a single string possibly delimited by path separators. Always returns an array of strings.
218 219 220 |
# File 'core-docs/toys/loader.rb', line 218 def split_path(str) # Source available in the toys-core gem end |