Class: KPM::Uninstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/kpm/uninstaller.rb

Instance Method Summary collapse

Constructor Details

#initialize(destination, logger = nil) ⇒ Uninstaller

Returns a new instance of Uninstaller.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kpm/uninstaller.rb', line 7

def initialize(destination, logger = nil)
  @logger = logger
  if @logger.nil?
    @logger = Logger.new(STDOUT)
    @logger.level = Logger::INFO
  end

  @destination = (destination || KPM::BaseInstaller::DEFAULT_BUNDLES_DIR)
  refresh_installed_plugins

  plugins_installation_path = File.join(@destination, 'plugins')
  @plugins_manager = PluginsManager.new(plugins_installation_path, @logger)

  sha1_file_path = File.join(@destination, KPM::BaseInstaller::SHA1_FILENAME)
  @sha1checker = KPM::Sha1Checker.from_file(sha1_file_path, @logger)
end

Instance Method Details

#uninstall_non_default_plugins(dry_run = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kpm/uninstaller.rb', line 32

def uninstall_non_default_plugins(dry_run = false)
  plugins = categorize_plugins

  if plugins[:to_be_deleted].empty?
    KPM.ui.say 'Nothing to do'
    return false
  end

  if dry_run
    msg = "The following plugin versions would be removed:\n"
    msg += plugins[:to_be_deleted].map { |p| "  #{p[0][:plugin_name]}: #{p[1]}" }.join("\n")
    msg += "\nThe following plugin versions would be kept:\n"
    msg += plugins[:to_keep].map { |p| "  #{p[0][:plugin_name]}: #{p[1]}" }.join("\n")
    KPM.ui.say msg
    false
  else
    plugins[:to_be_deleted].each do |p|
      remove_plugin_version(p[0], p[1])
    end
    true
  end
end

#uninstall_plugin(plugin, force = false, version = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/kpm/uninstaller.rb', line 24

def uninstall_plugin(plugin, force = false, version = nil)
  plugin_info = find_plugin(plugin)
  raise "No plugin with key/name '#{plugin}' found installed. Try running 'kpm inspect' for more info" unless plugin_info

  versions = version.nil? ? plugin_info[:versions].map { |artifact| artifact[:version] } : [version]
  remove_plugin_versions(plugin_info, force, versions)
end