Module: Kontena::PluginManager::Common

Constant Summary collapse

KRATES_PLUGIN =
'krates-plugin-%s'

Class Method Summary collapse

Class Method Details

.dummy_uiGem::StreamUI

Returns a rubygems user interaction module with minimal output.

Returns:

  • (Gem::StreamUI)

    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

Parameters:



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_dirString

Gem installation directory

Returns:



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

Parameters:



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

Returns:

  • (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?.

Returns:

  • (Boolean)

    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

.pluginsObject



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_clientKontena::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

Parameters:

  • pattern (String) (defaults to: nil)

    optional search pattern



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_uiObject

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