Class: VundleCli::Cleaner
- Inherits:
-
Object
- Object
- VundleCli::Cleaner
- Defined in:
- lib/vundle_cli/cleaner.rb
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#settings_dir ⇒ Object
readonly
Returns the value of attribute settings_dir.
-
#vimdir ⇒ Object
readonly
Returns the value of attribute vimdir.
-
#vimrc ⇒ Object
readonly
Returns the value of attribute vimrc.
Instance Method Summary collapse
- #clean ⇒ Object
-
#get_list ⇒ Object
Get a list of unused plugins.
-
#initialize(options, plugin) ⇒ Cleaner
constructor
A new instance of Cleaner.
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(, plugin) @options = @vimdir = file_validate(.vimdir, true) @settings_dir = file_validate(.settings, true) @vimrc = file_validate(.vimrc) @all = .all @force = .force @plugin = plugin end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
5 6 7 |
# File 'lib/vundle_cli/cleaner.rb', line 5 def all @all end |
#force ⇒ Object (readonly)
Returns the value of attribute force.
5 6 7 |
# File 'lib/vundle_cli/cleaner.rb', line 5 def force @force end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/vundle_cli/cleaner.rb', line 5 def @options end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
5 6 7 |
# File 'lib/vundle_cli/cleaner.rb', line 5 def plugin @plugin end |
#settings_dir ⇒ Object (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 |
#vimdir ⇒ Object (readonly)
Returns the value of attribute vimdir.
5 6 7 |
# File 'lib/vundle_cli/cleaner.rb', line 5 def vimdir @vimdir end |
#vimrc ⇒ Object (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
#clean ⇒ Object
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_list ⇒ Object
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 |