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_gem(gem_name, gem_version, gem_path, high_priority: false, source_name: nil, gem_toys_dir: nil, context_directory: nil) ⇒ self
Add a configuration gem source to the loader.
-
#add_git(git_remote, git_path, git_commit, high_priority: false, source_name: nil, 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, source_name: nil, 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, even if they are hidden or non-runnable.
-
#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, 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 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, gems_util: nil) ⇒ Loader
Create a Loader
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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, gems_util: 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.
127 128 129 130 131 132 |
# File 'core-docs/toys/loader.rb', line 127 def add_block(high_priority: false, source_name: nil, context_directory: nil, &block) # Source available in the toys-core gem end |
#add_gem(gem_name, gem_version, gem_path, high_priority: false, source_name: nil, gem_toys_dir: nil, context_directory: nil) ⇒ self
Add a configuration gem source to the loader.
185 186 187 188 189 190 191 |
# File 'core-docs/toys/loader.rb', line 185 def add_gem(gem_name, gem_version, gem_path, high_priority: false, source_name: nil, gem_toys_dir: nil, context_directory: nil) # Source available in the toys-core gem end |
#add_git(git_remote, git_path, git_commit, high_priority: false, source_name: nil, update: false, context_directory: nil) ⇒ self
Add a configuration git source to the loader.
155 156 157 158 159 160 161 |
# File 'core-docs/toys/loader.rb', line 155 def add_git(git_remote, git_path, git_commit, high_priority: false, source_name: nil, 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.
74 75 76 77 78 79 |
# File 'core-docs/toys/loader.rb', line 74 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, source_name: nil, 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.
104 105 106 107 108 109 |
# File 'core-docs/toys/loader.rb', line 104 def add_path_set(root_path, relative_paths, high_priority: false, source_name: nil, 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, even if they are hidden or non-runnable. Loads from the configuration if necessary.
257 258 259 |
# File 'core-docs/toys/loader.rb', line 257 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 the configuration if necessary. The list will be sorted by name.
242 243 244 245 246 247 248 |
# File 'core-docs/toys/loader.rb', line 242 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 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.
206 207 208 |
# File 'core-docs/toys/loader.rb', line 206 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.
222 223 224 |
# File 'core-docs/toys/loader.rb', line 222 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.
269 270 271 |
# File 'core-docs/toys/loader.rb', line 269 def split_path(str) # Source available in the toys-core gem end |