lib/boxy.rb in boxy-0.1.0 vs lib/boxy.rb in boxy-0.2.0

- old
+ new

@@ -1,8 +1,8 @@ require 'boxy/version' require 'boxy/dsl' -require 'bundler' +require 'highline' module Boxy def self.load_commands(url) Boxy::Dsl.interpret(url).uniq end @@ -14,25 +14,54 @@ end end def self.install(commands) + ensure_homebrew_installed + commands.each do |command| handler = @@handlers[command.type] - Bundler.with_clean_env do + with_clean_env do handler.install(command.name, command.options) end end end def self.register(type, handler) @@handlers ||= {} @@handlers[type] = handler end + + private + + + def self.ensure_homebrew_installed + installed = system 'which brew' + if not installed + cli = HighLine.new + do_install = cli.agree 'Homebrew is not installed, would you like to install it now? (y/n):' + if do_install + system '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"' + else + exit -1 + end + end + end + + def self.with_clean_env(&block) + begin + require 'bundler' + Bundler.with_clean_env(&block) + rescue LoadError + yield + end + end + end require 'boxy/brew' require 'boxy/brew_cask' require 'boxy/defaulty' require 'boxy/homesick' require 'boxy/luarock' +require 'boxy/mkdirs'