2014-04-13 08:46:20 -07:00
|
|
|
include Rake::DSL
|
|
|
|
require_relative 'homebrew'
|
|
|
|
|
|
|
|
module Rbenv
|
|
|
|
|
|
|
|
BREWS = %w{rbenv ruby-build rbenv-bundler rbenv-vars rbenv-gem-rehash}
|
|
|
|
|
2014-06-21 01:34:43 -07:00
|
|
|
GEM_BIN = "/usr/local/opt/rbenv/shims/gem"
|
|
|
|
|
2014-04-13 08:46:20 -07:00
|
|
|
def self.bootstrap
|
|
|
|
unless self.is_installed?
|
|
|
|
BREWS.each { |pkg| Homebrew.install pkg }
|
2014-06-21 02:40:15 -07:00
|
|
|
echo "Rbenv is installed! Restart the shell then rake."
|
|
|
|
exit
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.destroy
|
|
|
|
if self.is_installed?
|
|
|
|
BREWS.each { |pkg| Homebrew.remove pkg }
|
2014-06-18 12:51:08 -07:00
|
|
|
# sh_safe "rm -rf #{Homebrew.prefix 'rbenv'}"
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.install(version, gems=[])
|
|
|
|
unless self.is_version_installed?(version)
|
2014-06-18 12:51:08 -07:00
|
|
|
sh_safe "rbenv install #{version}"
|
2014-06-21 02:40:15 -07:00
|
|
|
sh_safe "RBENV_VERSION=#{version} #{GEM_BIN} install #{gems.join(' ')}"
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.update(version)
|
2014-06-21 01:34:43 -07:00
|
|
|
cmd = self._sudo(version)
|
|
|
|
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} update"
|
|
|
|
sh_safe "RBENV_VERSION=#{version} #{cmd} #{GEM_BIN} clean"
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.is_installed?
|
|
|
|
Homebrew.is_keg_installed? "rbenv"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.is_version_installed?(version)
|
2014-06-18 12:51:08 -07:00
|
|
|
system("rbenv versions | grep -w #{version} &>/dev/null")
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.installed_versions
|
|
|
|
`ls -1 #{Homebrew.prefix 'rbenv'}/versions`.split("\n")
|
|
|
|
end
|
|
|
|
|
2014-06-21 01:34:43 -07:00
|
|
|
def self._sudo(version)
|
|
|
|
if version == 'system'
|
|
|
|
return "sudo"
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-13 08:46:20 -07:00
|
|
|
end
|