Class: MultiRubyRunner::VersionManager::Rvm

Inherits:
MultiRubyRunner::VersionManager show all
Defined in:
lib/multi_ruby_runner/version_manager/rvm.rb

Overview

Represents the [rvm](rvm.io/) ruby version manager.

Instance Method Summary collapse

Methods inherited from MultiRubyRunner::VersionManager

detect, #initialize

Constructor Details

This class inherits a constructor from MultiRubyRunner::VersionManager

Instance Method Details

#activation_stringString

Returns the string to be executed in shell to activate rvm in a shell.

Returns:

  • (String)


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/multi_ruby_runner/version_manager/rvm.rb', line 37

def activation_string
  # Given the @ruby_executable_path, we can compute the rvm script path
  # that needs to be sourced:
  # /Users/username/.rvm/rubies/ruby-2.2.3/bin/ruby
  #               ~/.rvm/scripts/rvm
  script_path = @ruby_executable_path.match(
    /^.+(#{ Regexp.escape("/.rvm/") })(?=rubies)/
  )[0]
  if script_path.nil?
    raise RuntimeError.new("Could not detect rvm script path! (#{ @ruby_executable_path.inspect }")
  end
  script_path << 'scripts/rvm'
  # Rvm requires sourcing of script_path:
  "source #{ script_path }"
end

#compute_process_args(command_string, directory, options) ⇒ Hash

See MultiRubyRunner#execute_command_in_directory

Returns:

  • (Hash)

    entire_command: includes shell invocation,
                    ruby version manager activation and command
    blocking: Boolean
    environment_overrides: {
    

    }



15
16
17
18
19
20
21
22
23
24
# File 'lib/multi_ruby_runner/version_manager/rvm.rb', line 15

def compute_process_args(command_string, directory, options)
  {
    entire_command: [
      options[:shell_invocation],
      %('#{ shell_command_string(command_string, directory) }')
    ].join(' '),
    blocking: options[:blocking],
    environment_overrides: {},
  }
end

#shell_command_string(command_string, directory) ⇒ Object

Returns the command string to be passed to the shell



27
28
29
30
31
32
33
# File 'lib/multi_ruby_runner/version_manager/rvm.rb', line 27

def shell_command_string(command_string, directory)
  [
    activation_string, # activate rvm
    "cd #{ directory }", # cd into the directory containing .ruby-version file
    command_string, # execute command
  ].join('; ')
end