Class: VundleCli::Cleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/vundle_cli/cleaner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, plugin) ⇒ Cleaner

Returns a new instance of Cleaner.



7
8
9
10
11
12
13
14
15
# File 'lib/vundle_cli/cleaner.rb', line 7

def initialize(options, plugin)
  @options = options
  @vimdir = file_validate(options.vimdir, true)
  @settings_dir = file_validate(options.settings, true)
  @vimrc = file_validate(options.vimrc)
  @all = options.all
  @force = options.force
  @plugin = plugin
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def all
  @all
end

#forceObject (readonly)

Returns the value of attribute force.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def force
  @force
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def options
  @options
end

#pluginObject (readonly)

Returns the value of attribute plugin.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def plugin
  @plugin
end

#settings_dirObject (readonly)

Returns the value of attribute settings_dir.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def settings_dir
  @settings_dir
end

#vimdirObject (readonly)

Returns the value of attribute vimdir.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def vimdir
  @vimdir
end

#vimrcObject (readonly)

Returns the value of attribute vimrc.



5
6
7
# File 'lib/vundle_cli/cleaner.rb', line 5

def vimrc
  @vimrc
end

Instance Method Details

#cleanObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vundle_cli/cleaner.rb', line 17

def clean
  if @all or @options.list
    unused_plugins = get_list
  end

  if @options.list
    say "Unused plugins:"
    say unused_plugins.join("\n") unless unused_plugins.empty?
    puts_separator
  end
  if @all
    uninstaller = Uninstaller.new(@options)
    unused_plugins.each do |plugin_name| 
      say "Cleaning #{plugin_name}..."
      uninstaller.delete_setting_file(plugin_name)
      uninstaller.delete_plugin_dir(plugin_name)
    end
  elsif not @plugin.nil?
    # Only clean up unused plugin.
    open(@vimrc, 'r').each { |l| 
      next unless l.chomp =~ /(Bundle|Plugin) .*#{Regexp.quote(@plugin)}.*/
      say_error "Can't clean this plugin since it's installed in your .vimrc. Please use command `rm` to uninstall it."
      return
    }

    uninstaller = Uninstaller.new(@options, @plugin)
    uninstaller.rm(false)
  end
end

#get_listObject

Get a list of unused plugins.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vundle_cli/cleaner.rb', line 48

def get_list
  # Get a list of plugin directories (basenames only).
  all_plugins = Array.new
  all_plugins = Dir["#{@vimdir}/bundle/*/"].map { |b|
    File.basename(b)
  }

  # Get a list of installed plugins.
  finder = Finder.new(@options)
  installed_plugins = Array.new
  installed_plugins = finder.get_list.map { |b|
    plugin_base_name(b)
  }

  all_plugins - installed_plugins
end