Module: BinInstall::Ruby::Rbenv

Defined in:
lib/bin_install/ruby/rbenv.rb

Constant Summary collapse

DOCTOR =
'curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash'.freeze

Class Method Summary collapse

Class Method Details

.abort_install!Object



74
75
76
77
78
79
80
81
82
# File 'lib/bin_install/ruby/rbenv.rb', line 74

def self.abort_install!
  puts 'Warning rbenv shims are not loaded.'.yellow
  puts 'Try closing this window and restarting your shell session.'.yellow
  puts "\n"
  puts 'Rerun the installer with:'
  puts '$ bin/install'.cyan
  puts "\n"
  abort('Aborting install.'.red)
end

.doctorObject



62
63
64
# File 'lib/bin_install/ruby/rbenv.rb', line 62

def self.doctor
  system(DOCTOR)
end

.doctor!Object



66
67
68
# File 'lib/bin_install/ruby/rbenv.rb', line 66

def self.doctor!
  BinInstall.system!(DOCTOR)
end

.installObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bin_install/ruby/rbenv.rb', line 6

def self.install
  if Ruby::Rvm.installed?
    puts 'RVM is already installed. Skipping rbenv install.'.yellow
  else
    puts 'Installing rbenv...'.white
    Brew::Package.install('rbenv')
    Brew::Package.install_or_upgrade('ruby-build')
    Shell.append_to_profiles(%{eval "$(rbenv init -)"\n})
    require_shims!
    install_ruby
    doctor
  end
end

.install!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bin_install/ruby/rbenv.rb', line 20

def self.install!
  if Ruby::Rvm.installed?
    abort('RVM is already installed. Aborting rbenv install.'.red)
  else
    puts 'Installing rbenv...'.white
    Brew::Package.install!('rbenv')
    Brew::Package.install_or_upgrade!('ruby-build')
    Shell.append_to_profiles!(%{eval "$(rbenv init -)"\n})
    require_shims!
    install_ruby!
    doctor!
  end
end

.install_ruby(version = Ruby.required_ruby_version) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bin_install/ruby/rbenv.rb', line 34

def self.install_ruby(version = Ruby.required_ruby_version)
  puts "Installing Ruby #{version}...".white

  if version
    if Ruby.ruby_version_installed?(version)
      puts "Ruby #{version} is already installed. Skipping Ruby #{version} install.".blue
    else
      system("rbenv install #{version}")
    end
  else
    puts 'Unknown Ruby version. Create .ruby-version file.'
  end
end

.install_ruby!(version = Ruby.required_ruby_version) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bin_install/ruby/rbenv.rb', line 48

def self.install_ruby!(version = Ruby.required_ruby_version)
  puts "Installing Ruby #{version}...".white

  if version
    if Ruby.ruby_version_installed?(version)
      puts "Ruby #{version} is already installed. Skipping Ruby #{version} install.".blue
    else
      BinInstall.system!("rbenv install #{version}")
    end
  else
    abort('Unknown Ruby version. Create .ruby-version file.'.red)
  end
end

.installed?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/bin_install/ruby/rbenv.rb', line 100

def self.installed?
  Shell.executable_exists?('rbenv')
end

.rehashObject



84
85
86
# File 'lib/bin_install/ruby/rbenv.rb', line 84

def self.rehash
  system('rbenv rehash')
end

.rehash!Object



88
89
90
# File 'lib/bin_install/ruby/rbenv.rb', line 88

def self.rehash!
  BinInstall.system!('rbenv rehash')
end

.require_shims!Object



70
71
72
# File 'lib/bin_install/ruby/rbenv.rb', line 70

def self.require_shims!
  abort_install! unless `#{DOCTOR}`.include?('Checking for rbenv shims in PATH: OK')
end

.versionObject



92
93
94
# File 'lib/bin_install/ruby/rbenv.rb', line 92

def self.version
  system('rbenv version')
end

.version!Object



96
97
98
# File 'lib/bin_install/ruby/rbenv.rb', line 96

def self.version!
  BinInstall.system!('rbenv version')
end