lib/ruby/dots/bootstrap.rb in zsh_dots-0.5.9 vs lib/ruby/dots/bootstrap.rb in zsh_dots-0.6.0

- old
+ new

@@ -1,54 +1,74 @@ +require 'dots/packages' + module Dots module Bootstrap include Thor::Actions - # These are the programs we are going to download from Homebrew. - PROGRAMS = %w(git ruby python vim pip hub) - PACKAGES = %w(httpie aws) - # Install C binaries, Python programs, and other useful tools - # from Homebrew. + # from Homebrew. Install Homebrew if it isn't already installed, + # then recursively call this method to install packages. def install_programs if installed? "brew" - programs_to_install = PROGRAMS.reduce([]) { |programs, program| - programs << program unless installed? program - }.join " " - - system "brew install #{programs_to_install}" \ - unless programs_to_install.empty? - install_packages + install_packages and install_configuration + elsif @homebrew.present? # make sure we're not in an infinite loop + puts "WARNING: Homebrew can not install. Exiting.." and exit(1) else + @homebrew = true # used when the if statement fails twice install_homebrew and install_programs end end - # Install the latest version of all gems to the global gemset. These - # gems are configured in +~/.Gemfile+. - def install_bundle - system "cd && #{install_bundler} && #{install_global_gemset}" + # When Homebrew is installed, use it to install Python and Ruby, then + # install necessary packages for Python and Ruby. + def install_packages + %w(system python ruby).each { |l| send "install_#{l}_packages" } end - # Install Python packages from pip. Pip! - def install_packages - system "pip install #{PACKAGES.join(' ')}" + # Install configuration file templates that for one reason or another + # we can't include in the repo directly. Usually due to exposed passwords + # or API keys. + def install_configuration + system "mkdir -p ~/.irssi && cp -R ~/.dots/etc/irssi/** ~/.irssi" end private def installed? command `which #{command}` != "" end - def install_bundler - "gem install bundler" + def installed_and_not_ruby? command + installed?(command) && command != 'ruby' end - def install_global_gemset - "gem install #{Dots.gems}" - end - - # Install the latest version of the Homebrew package manager. def install_homebrew %x[ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"] + end + + def install_system_packages + programs_to_install = system_packages.reduce([]) { |programs, program| + programs << program unless installed_and_not_ruby? program + }.join " " + + system "brew install #{programs_to_install}" \ + unless programs_to_install.empty? + end + + def install_ruby_packages + "gem install #{ruby_packages}" + end + + def install_python_packages + system "pip install #{python_packages}" + end + + %w(system python ruby).each do |language| + define_method "#{language}_packages" do + packages.for language + end + end + + def packages + @packages ||= Packages.new end end end