Module: Kontena::PluginManager::Common
- Included in:
- Cli::Plugins::InstallCommand, Cli::Plugins::ListCommand, Cli::Plugins::SearchCommand, Cli::Plugins::UpgradeCommand, Cleaner, Installer, Loader, Uninstaller
- Defined in:
- lib/kontena/plugin_manager/common.rb
Constant Summary collapse
- KRATES_PLUGIN =
'krates-plugin-%s'
Class Method Summary collapse
-
.dummy_ui ⇒ Gem::StreamUI
A rubygems user interaction module with minimal output.
-
.gem_versions(plugin_name) ⇒ Object
Retrieve plugin versions from rubygems.
-
.install_dir ⇒ String
Gem installation directory.
-
.installed(plugin_name) ⇒ Object
Find a plugin by name from installed plugins.
- .installed?(plugin_name) ⇒ Boolean
-
.plugin_debug? ⇒ Boolean
Is the CLI in plugin debugging mode?.
- .plugins ⇒ Object
-
.prefix(plugin_name) ⇒ Object
Prefix a plugin name into a gem name (hello to krates-plugin-hello).
- .rubygems_client ⇒ Kontena::PluginManager::RubygemsClient
-
.search_plugins(pattern = nil) ⇒ Object
Search rubygems for kontena plugins.
-
.use_dummy_ui ⇒ Object
Tell rubygems to use the dummy ui as default user interaction.
Class Method Details
.dummy_ui ⇒ Gem::StreamUI
Returns a rubygems user interaction module with minimal output.
18 19 20 |
# File 'lib/kontena/plugin_manager/common.rb', line 18 def dummy_ui Gem::StreamUI.new(StringIO.new, StringIO.new, StringIO.new, false) end |
.gem_versions(plugin_name) ⇒ Object
Retrieve plugin versions from rubygems
78 79 80 |
# File 'lib/kontena/plugin_manager/common.rb', line 78 def gem_versions(plugin_name) rubygems_client.versions(prefix(plugin_name)) end |
.install_dir ⇒ String
Gem installation directory
52 53 54 55 56 57 58 59 60 |
# File 'lib/kontena/plugin_manager/common.rb', line 52 def install_dir return @install_dir if @install_dir install_dir = File.join(Dir.home, '.krates', 'gems', RUBY_VERSION) unless File.directory?(install_dir) require 'fileutils' FileUtils.mkdir_p(install_dir, mode: 0700) end @install_dir = install_dir end |
.installed(plugin_name) ⇒ Object
Find a plugin by name from installed plugins
39 40 41 42 |
# File 'lib/kontena/plugin_manager/common.rb', line 39 def installed(plugin_name) search = prefix(plugin_name) plugins.find {|plugin| plugin.name == search } end |
.installed?(plugin_name) ⇒ Boolean
45 46 47 |
# File 'lib/kontena/plugin_manager/common.rb', line 45 def installed?(plugin_name) !installed(plugin_name).nil? end |
.plugin_debug? ⇒ Boolean
Returns is the CLI in plugin debugging mode?.
12 13 14 |
# File 'lib/kontena/plugin_manager/common.rb', line 12 def plugin_debug? @plugin_debug ||= ENV['CMD_DEBUG'] == 'plugin' end |
.plugins ⇒ Object
83 84 85 |
# File 'lib/kontena/plugin_manager/common.rb', line 83 def plugins Kontena::PluginManager.plugins end |
.prefix(plugin_name) ⇒ Object
Prefix a plugin name into a gem name (hello to krates-plugin-hello)
30 31 32 33 34 |
# File 'lib/kontena/plugin_manager/common.rb', line 30 def prefix(plugin_name) return KRATES_PLUGIN % nil if plugin_name.nil? || plugin_name.empty? return plugin_name if plugin_name.start_with?('krates-plugin-') || plugin_name.include?('.') KRATES_PLUGIN % plugin_name end |
.rubygems_client ⇒ Kontena::PluginManager::RubygemsClient
64 65 66 |
# File 'lib/kontena/plugin_manager/common.rb', line 64 def rubygems_client @rubygems_client ||= Kontena::PluginManager::RubygemsClient.new end |
.search_plugins(pattern = nil) ⇒ Object
Search rubygems for kontena plugins
71 72 73 |
# File 'lib/kontena/plugin_manager/common.rb', line 71 def search_plugins(pattern = nil) rubygems_client.search(prefix(pattern)) end |
.use_dummy_ui ⇒ Object
Tell rubygems to use the dummy ui as default user interaction
24 25 26 |
# File 'lib/kontena/plugin_manager/common.rb', line 24 def use_dummy_ui Gem::DefaultUserInteraction.ui = dummy_ui end |