Class: VundleMigrator::Migrator
- Inherits:
-
Object
- Object
- VundleMigrator::Migrator
- Defined in:
- lib/vundle_migrator.rb
Constant Summary collapse
- VIMRC_SOURCE =
"\" load vundle plugins\n" \ "source ~/.vim/vundle/plugins.vim\n\n"
- PLUGINS_START =
"set nocompatible\n" \ "filetype off\n" \ "set rtp+=~/.vim/bundle/Vundle.vim\n\n" \ "call vundle#begin()\n\n"
- PLUGINS_END =
"\ncall vundle#end()\n\n" \ "filetype plugin indent on"
Instance Attribute Summary collapse
-
#plugins ⇒ Object
readonly
Returns the value of attribute plugins.
Instance Method Summary collapse
- #create_plugins_file ⇒ Object
- #create_plugins_list ⇒ Object
- #create_vundle_folder ⇒ Object
- #dry_run ⇒ Object
-
#initialize(vimrc, source, destination) ⇒ Migrator
constructor
A new instance of Migrator.
- #prepend_vimrc ⇒ Object
- #print_file_contents ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(vimrc, source, destination) ⇒ Migrator
Returns a new instance of Migrator.
24 25 26 27 28 29 30 |
# File 'lib/vundle_migrator.rb', line 24 def initialize(vimrc, source, destination) @vimrc = vimrc @source = source || "#{Dir.home}/.vim/bundle" @destination = destination || "#{Dir.home}/.vim/vundle/plugins.vim" @entries = Dir.entries(@source) - %w(. ..) @plugins = [] end |
Instance Attribute Details
#plugins ⇒ Object (readonly)
Returns the value of attribute plugins.
11 12 13 |
# File 'lib/vundle_migrator.rb', line 11 def plugins @plugins end |
Instance Method Details
#create_plugins_file ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vundle_migrator.rb', line 62 def create_plugins_file puts "creating #{@destination}" File.open(@destination, "w") do |f| f.write(PLUGINS_START) @plugins.each do |plugin| f.write("#{plugin}\n") end f.write(PLUGINS_END) end end |
#create_plugins_list ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/vundle_migrator.rb', line 47 def create_plugins_list puts "creating list of plugins" @plugins = @entries.map do |plugin_directory| Dir.chdir("#{@source}/#{plugin_directory}") do package = `git remote -v`.match(/com[\/|:](.+)\.git/)[1] "Plugin '#{package}'" end end end |
#create_vundle_folder ⇒ Object
57 58 59 60 |
# File 'lib/vundle_migrator.rb', line 57 def create_vundle_folder puts "creating folder at #{File.dirname(@destination)}" FileUtils.mkdir_p(File.dirname(@destination)) end |
#dry_run ⇒ Object
42 43 44 45 |
# File 'lib/vundle_migrator.rb', line 42 def dry_run create_plugins_list print_file_contents end |
#prepend_vimrc ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vundle_migrator.rb', line 75 def prepend_vimrc puts "adding 'source vundle' to #{@vimrc}" File.rename("#{@vimrc}", "#{@vimrc}.old") File.open("#{@vimrc}", 'w') do |f| f.puts VIMRC_SOURCE File.foreach("#{@vimrc}.old") do |l| f.puts l end end FileUtils.remove("#{@vimrc}.old") end |
#print_file_contents ⇒ Object
89 90 91 92 93 94 |
# File 'lib/vundle_migrator.rb', line 89 def print_file_contents puts "file contents:\n------\n" puts PLUGINS_START puts @plugins puts PLUGINS_END end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/vundle_migrator.rb', line 32 def run puts "starting the migration" create_plugins_list create_vundle_folder create_plugins_file prepend_vimrc puts "migration finished" puts "don't forget to run ':PluginInstall' after loading vim" end |