Class: Chef::Knife::SubcommandLoader::GemGlobLoader
- Inherits:
-
Chef::Knife::SubcommandLoader
- Object
- Chef::Knife::SubcommandLoader
- Chef::Knife::SubcommandLoader::GemGlobLoader
- Defined in:
- lib/chef/knife/core/gem_glob_loader.rb
Instance Attribute Summary
Attributes inherited from Chef::Knife::SubcommandLoader
Instance Method Summary collapse
- #find_subcommands_via_rubygems ⇒ Object
-
#gem_and_builtin_subcommands ⇒ Object
Returns a Hash of paths to knife commands built-in to chef, or installed via gem.
- #subcommand_files ⇒ Object
Methods inherited from Chef::Knife::SubcommandLoader
autogenerated_manifest?, #command_class_from, #find_longest_key, #find_subcommands_via_dirglob, for_config, #force_load, gem_glob_loader, generate_hash, #guess_category, #initialize, #list_commands, #load_command, #load_commands, plugin_manifest, plugin_manifest?, plugin_manifest_path, #positional_arguments, #site_subcommands, write_hash
Constructor Details
This class inherits a constructor from Chef::Knife::SubcommandLoader
Instance Method Details
#find_subcommands_via_rubygems ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/chef/knife/core/gem_glob_loader.rb', line 48 def find_subcommands_via_rubygems files = find_files_latest_gems "chef/knife/*.rb" version_file_match = /#{Regexp.escape(File.join('chef', 'knife', 'version'))}$/ subcommand_files = {} files.each do |file| rel_path = file[/(.*)(#{Regexp.escape File.join('chef', 'knife', '')}.*)\.rb/, 2] # When not installed as a gem (ChefDK/appbundler in particular), AND # a different version of Chef is installed via gems, `files` will # include some files from the 'other' Chef install. If this contains # a knife command that doesn't exist in this version of Chef, we will # get a LoadError later when we try to require it. next if from_different_chef_version?(file) # Exclude knife/chef/version. It's not a knife command, and force-loading # when we load all of these files will emit constant-already-defined warnings next if rel_path&.match?(version_file_match) subcommand_files[rel_path] = file end subcommand_files.merge(find_subcommands_via_dirglob) end |
#gem_and_builtin_subcommands ⇒ Object
Returns a Hash of paths to knife commands built-in to chef, or installed via gem. If rubygems is not installed, falls back to globbing the knife directory. The Hash is of the form => “/absolute/path” – Note: the “right” way to load the plugins is to require the relative path, i.e.,
require 'chef/knife/command'
but we’re getting frustrated by bugs at every turn, and it’s slow besides. So subcommand loader has been modified to load the plugins by using Kernel.load with the absolute path.
41 42 43 44 45 46 |
# File 'lib/chef/knife/core/gem_glob_loader.rb', line 41 def gem_and_builtin_subcommands require "rubygems" unless defined?(Gem) find_subcommands_via_rubygems rescue LoadError find_subcommands_via_dirglob end |
#subcommand_files ⇒ Object
28 29 30 |
# File 'lib/chef/knife/core/gem_glob_loader.rb', line 28 def subcommand_files @subcommand_files ||= (gem_and_builtin_subcommands.values + site_subcommands).flatten.uniq end |