Class: MultiRubyRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_ruby_runner.rb,
lib/multi_ruby_runner/version.rb,
lib/multi_ruby_runner/version_manager.rb,
lib/multi_ruby_runner/version_manager/rvm.rb,
lib/multi_ruby_runner/version_manager/none.rb,
lib/multi_ruby_runner/version_manager/rbenv.rb

Overview

Allows calling of Ruby code in various Ruby environments.

Defined Under Namespace

Classes: VersionManager

Constant Summary collapse

VERSION =
"1.0.5"

Instance Method Summary collapse

Constructor Details

#initializeMultiRubyRunner

Returns a new instance of MultiRubyRunner.



10
11
# File 'lib/multi_ruby_runner.rb', line 10

def initialize
end

Instance Method Details

#execute_command_in_directory(command_string, directory, options = {}) ⇒ String, ...

Executes a command in a directory. Command will be executed in the ruby environment specified in ‘.ruby-version` file in `directory`. Returns stdout in the blocking form and pid of child process in the non-blocking form.

Parameters:

  • command_string (String)

    the shell command to run in directory

  • directory (String)

    the dir containing the “.ruby-version” file

  • options (Hash, optional) (defaults to: {})

Options Hash (options):

  • shell_invocation (String, optional)

    what shell to use, defaults to bash

  • blocking (Boolean, optional)

    defaults to true.

  • ruby_engine_invocation_override (String, optional)

    Can be used when no Ruby version manager is present, e.g., in a docker install. Example: “jruby -S ”

Returns:

  • (String, Integer, Nil)

    STDOUT output when blocking, pid when non-blocking.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/multi_ruby_runner.rb', line 27

def execute_command_in_directory(command_string, directory, options = {})
  shell_path = ENV['SHELL'] || '/bin/bash'
  options = {
    blocking: true,
    shell_invocation: "#{ shell_path } -c",
  }.merge(options)
  process_args = ruby_version_manager.compute_process_args(
    command_string,
    directory,
    options
  )
  execute_command(process_args)
end

#ruby_version_managerMultiRubyRunner::VersionManager

Returns the ruby version manager used

Returns:



43
44
45
# File 'lib/multi_ruby_runner.rb', line 43

def ruby_version_manager
  VersionManager.detect
end