Class: Ober::Runner::RVM

Inherits:
Ober::Runner show all
Defined in:
lib/ober/runner/rvm.rb

Instance Method Summary collapse

Methods inherited from Ober::Runner

#run, #run_silent

Constructor Details

#initialize(rvm) ⇒ RVM

Returns a new instance of RVM.



5
6
7
8
9
10
# File 'lib/ober/runner/rvm.rb', line 5

def initialize rvm
  @rvm_source_path = source(rvm)
  fail "No such RVM version. (#{rvm} not found)" unless @rvm_source_path

  detect_environment_for_rvm
end

Instance Method Details

#detect_environment_for_rvmObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ober/runner/rvm.rb', line 16

def detect_environment_for_rvm
  echo_string = ''
  variables.each { |v| echo_string << "echo $#{v}; " }

  output = run_silent(%Q(
    bash -c 'source #{@rvm_source_path}; #{echo_string}'
  ).strip)

  @env = {}
  variables.zip(output.lines).each do |var, val|
    val.chomp!
    @env[var] = val.size == 0 ? nil : val 
  end
end

#produce_shellout(cmd, opts) ⇒ Object



31
32
33
# File 'lib/ober/runner/rvm.rb', line 31

def produce_shellout cmd, opts
  Mixlib::ShellOut.new(cmd, opts.merge(environment: @env))
end

#source(version) ⇒ Object

You should find version by running

rvm env --path

and taking the last part of the path as your version. Unlike what rvm accepts, we’re kind of picky here.



42
43
44
45
46
47
# File 'lib/ober/runner/rvm.rb', line 42

def source version
  # Locate rvm installation: 
  ["#{ENV['HOME']}/.rvm/environments"].
    map { |path| File.join(path, version) }.
    find { |path| File.exist?(path) }
end

#variablesObject



12
13
14
15
# File 'lib/ober/runner/rvm.rb', line 12

def variables 
  %w(PATH rvm_env_string rvm_path rvm_ruby_string rvm_gemset_name 
    RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC MAGLEV_HOME RBXOPT)
end