class RVM::Environment

Implements the actual wrapper around the api. For more information about this design, see the RVM module.

Constants

PREFIX_OPTIONS

Attributes

environment_name[R]
shell_wrapper[R]

Public Class Methods

config_value_for(value) click to toggle source

Gets the default option or the current environment variable for a given env var.

# File lib/rvm/environment/configuration.rb, line 40
def self.config_value_for(value)
  value = value.to_s
  config[value] || ENV[value]
end
current() click to toggle source

Returns the currentl environment. Note that when the ruby is changed, this is reset - Also, if the gemset is changed it will also be reset.

# File lib/rvm/environment/utility.rb, line 42
def self.current
  @current_environment ||= Environment.new(current_environment_id)
end
current_environment_id() click to toggle source

Returns the environment identifier for the current environment, as determined from the GEM_HOME.

# File lib/rvm/environment/utility.rb, line 13
def self.current_environment_id
  @current_environment_id ||= begin
    gem_home = ENV['GEM_HOME'].to_s.strip
    if !gem_home.empty? && gem_home =~ /rvm\/gems\//
      File.basename(gem_home)
    else
      matching_path = $:.select { |item| item =~ /rvm\/rubies/ }.first
      matching_path.to_s.gsub(/^.*rvm\/rubies\//, '').split('/')[0] || "system"
    end
  end
end
current_ruby_string() click to toggle source

Returns the ruby string that represents the current environment.

# File lib/rvm/environment/utility.rb, line 26
def self.current_ruby_string
  identifier_to_ruby_string(current_environment_id)
end
default_rvm_path() click to toggle source
# File lib/rvm/environment/utility.rb, line 6
def self.default_rvm_path
  value = %x`bash '#{File.expand_path('../shell/calculate_rvm_path.sh', File.dirname(__FILE__))}'`.strip
  $?.success? && !value.empty? ? File.expand_path(value) : nil
end
define_config_accessor(*args) click to toggle source

Define the config accessor, which basically uses ::config_value_for and the linke to set the env variable.

# File lib/rvm/environment/configuration.rb, line 6
def self.define_config_accessor(*args)
  singleton = (class << self; self; end)
  args.each do |arg|
    singleton.send(:define_method, arg)        { RVM::Environment.config_value_for(arg) }
    singleton.send(:define_method, :"#{arg}=") { |v| RVM::Environment.merge_config! arg => v }
  end
end
identifier_to_gemset_name(identifier) click to toggle source
# File lib/rvm/environment/utility.rb, line 35
def self.identifier_to_gemset_name(identifier)
  identifier.gsub(/^.*@/, '')
end
identifier_to_ruby_string(identifier) click to toggle source

Converts a ruby identifier (string + gemset) to just the ruby string.

# File lib/rvm/environment/utility.rb, line 31
def self.identifier_to_ruby_string(identifier)
  identifier.gsub(/@.*$/, '')
end
new(environment_name = "default", options = {}) click to toggle source

Creates a new environment with the given name and optionally a set of extra environment variables to be set on load.

# File lib/rvm/environment.rb, line 22
def initialize(environment_name = "default", options = {})
  merge_config! options
  @environment_name = environment_name
  @shell_wrapper = Shell.default_wrapper.new
  @shell_wrapper.setup do |s|
    source_rvm_environment
    use_rvm_environment
  end
end
reset_current!() click to toggle source

Sets the current environment back to the currently running ruby or the system env (if it can't be determined from GEM_HOME).

# File lib/rvm/environment/utility.rb, line 48
def self.reset_current!
  @current_environment = nil
end

Protected Class Methods

environment_with_gemset(environment, gemset) click to toggle source

Given an environment identifier, it will add the the given gemset to the end to form a qualified identifier name.

# File lib/rvm/environment/utility.rb, line 114
def self.environment_with_gemset(environment, gemset)
  environment_name, gemset_name = environment.split("@", 2)
  environment_name = "default"     if environment_name.to_s.empty?
  environment_name << "@#{gemset}" unless gemset.to_s.empty?
  environment_name
end

Public Instance Methods

alias_create(name, ruby_string) click to toggle source

Creates an alias with the given name.

# File lib/rvm/environment/alias.rb, line 27
def alias_create(name, ruby_string)
  rvm(:alias, :create, name.to_s, ruby_string.to_s).successful?
end
alias_delete(name) click to toggle source

Deletes an alias and returns the exit status.

# File lib/rvm/environment/alias.rb, line 22
def alias_delete(name)
  rvm(:alias, :delete, name.to_s).successful?
end
alias_list() click to toggle source

Returns a hash of aliases.

# File lib/rvm/environment/alias.rb, line 5
def alias_list
  lines = normalize_array(rvm(:alias, :list).stdout)
  lines.inject({}) do |acc, current|
    alias_name, ruby_string = current.to_s.split(" => ")
    unless alias_name.empty? || ruby_string.empty?
      acc[alias_name] = ruby_string
    end
    acc
  end
end
alias_show(name) click to toggle source

Shows the full ruby string that a given alias points to.

# File lib/rvm/environment/alias.rb, line 17
def alias_show(name)
  normalize rvm(:alias, :show, name.to_s).stdout
end
aliases() click to toggle source

Returns an aliases proxy which can be used in a more Ruby-like manner.

# File lib/rvm/environment/alias.rb, line 32
def aliases
  @aliases ||= AliasWrapper.new(self)
end
chdir(dir) { || ... } click to toggle source

Run commands inside the given directory.

# File lib/rvm/environment/utility.rb, line 76
def chdir(dir)
  run_silently :pushd, dir.to_s
  result = Dir.chdir(dir) { yield }
  run_silently :popd
  result
end
cleanup() click to toggle source

Returns the ruby-like interface defined by CleanupWrapper

# File lib/rvm/environment/cleanup.rb, line 12
def cleanup
  @cleanup_wrapper ||= CleanupWrapper.new(self)
end
config_value_for(key, default = nil, check_live = true) click to toggle source

Returns the value for a configuration option (mapping to an environment variable). If check_live is true (which it is by default), it will also check the environment for a value.

# File lib/rvm/environment/configuration.rb, line 48
def config_value_for(key, default = nil, check_live = true)
  key = key.to_s
  value = check_live ? self[key.to_s] : nil
  value || config[key] || self.class.config_value_for(key) || default
end
default_wrappers(ruby_string, *binaries) click to toggle source

Generates the default wrappers.

# File lib/rvm/environment/wrapper.rb, line 11
def default_wrappers(ruby_string, *binaries)
  wrapper ruby_string, '', *binaries
end
defined_config() click to toggle source

Returns a hash of all of the user defined configuration.

# File lib/rvm/environment/configuration.rb, line 55
def defined_config
  self.class.config.merge(self.config)
end
env() click to toggle source

Returns a ruby-like wrapper for the env functions

# File lib/rvm/environment/env.rb, line 22
def env
  @env_wrapper ||= EnvWrapper.new(self)
end
env_contents() click to toggle source

Returns the contents of the env file.

env.env_contents # => ['export PATH= .…', …]

# File lib/rvm/environment/env.rb, line 8
def env_contents
  rvm(:env, environment_name).stdout.split
end
env_path() click to toggle source

Returns the path to the env file Suppose that you are in the 1.9.2 environment.

env.env_path # => “~/.rvm/environments/ruby-1.9.2-p0”

# File lib/rvm/environment/env.rb, line 17
def env_path
  normalize_array rvm(:env, environment_name, :path => true).stdout
end
exec(command, *args) click to toggle source

Executes a command, replacing the current shell. exec is a bit of an odd ball compared to the others, since it has to use the Kernel.exec builtin.

# File lib/rvm/environment/sets.rb, line 63
def exec(command, *args)
  command = @shell_wrapper.build_cli_call(:exec, [command] + args)
  Kernel.exec "bash", "-c", "source '#{env_path}'; #{command}"
end
expanded_name() click to toggle source

Returns the expanded name, using the same method as used by the rvm command line.

Suppose that you are in the 1.9.2 patchlevel Environment.

env.expanded_name # => “ruby-1.9.2-p0”

# File lib/rvm/environment.rb, line 42
def expanded_name
  @expanded_name ||= tools_identifier.to_s
end
gemset() click to toggle source

Returns the Ruby-like wrapper for gemset operations.

# File lib/rvm/environment/gemset.rb, line 107
def gemset
  @gemset_wrapper ||= GemsetWrapper.new(self)
end
gemset_copy(from, to) click to toggle source

Copies the gems between two different gemsets.

# File lib/rvm/environment/gemset.rb, line 31
def gemset_copy(from, to)
  rvm(:gemset, :copy, from, to).successful?
end
gemset_create(*names) click to toggle source

Creates a new gemset with the given name.

# File lib/rvm/environment/gemset.rb, line 25
def gemset_create(*names)
  names = names.flatten
  rvm(:gemset, :create, *names).successful?
end
gemset_delete(name) click to toggle source

Deletes the gemset with a given name.

# File lib/rvm/environment/gemset.rb, line 36
def gemset_delete(name)
  run("echo 'yes' | rvm", :gemset, :delete, name.to_s).successful?
end
gemset_dump(gemset_or_file = nil)
Alias for: gemset_export
gemset_empty() click to toggle source

Removes all gem-related stuff from the current gemset.

# File lib/rvm/environment/gemset.rb, line 41
def gemset_empty
  run("echo 'yes' | rvm", :gemset, :empty).successful?
end
gemset_export(gemset_or_file = nil) click to toggle source

Exports a gemset.

# File lib/rvm/environment/gemset.rb, line 14
def gemset_export(gemset_or_file = nil)
  args = [gemset_or_file].compact
  rvm(:gemset, :export, *args).successful?
end
Also aliased as: gemset_dump
gemset_globalcache(enable = true) click to toggle source

Enable or disable the rvm gem global cache.

# File lib/rvm/environment/gemset.rb, line 66
def gemset_globalcache(enable = true)
  case enable
    when "enabled", :enabled
      run(:__rvm_using_gemset_globalcache).successful?
    when true, "enable", :enable
      rvm(:gemset, :globalcache, :enable).successful?
    when false, "disable", :disable
      rvm(:gemset, :globalcache, :disable).successful?
    else
      false
  end
end
gemset_import(file_prefix = nil) click to toggle source

Loads a gemset into the current environment. If an argument is given, it will load it from file_prefix.gems

# File lib/rvm/environment/gemset.rb, line 7
def gemset_import(file_prefix = nil)
  args = [file_prefix].compact
  rvm(:gemset, :import, *args).successful?
end
Also aliased as: gemset_load
gemset_initial() click to toggle source

Initializes gemsets for a given ruby.

# File lib/rvm/environment/gemset.rb, line 61
def gemset_initial
  rvm(:gemset, :initial).successful?
end
gemset_list() click to toggle source
# File lib/rvm/environment/gemset.rb, line 20
def gemset_list
  normalize_array rvm(:gemset, :list).stdout
end
gemset_load(file_prefix = nil)
Alias for: gemset_import
gemset_pristine() click to toggle source

Resets the current gemset to a pristine state.

# File lib/rvm/environment/gemset.rb, line 46
def gemset_pristine
  rvm(:gemset, :pristine).successful?
end
gemset_prune() click to toggle source

Prunes the gem cache for the current ruby.

# File lib/rvm/environment/gemset.rb, line 56
def gemset_prune
  rvm(:gemset, :prune).successful?
end
gemset_update() click to toggle source

Updates all gems in the current gemset.

# File lib/rvm/environment/gemset.rb, line 51
def gemset_update
  rvm(@environment_name, :gemset, :update).successful?
end
gemset_use(gemset, options = {}) click to toggle source

Changes the current environments gemset. If :replace_env is passed and the ruby is compatible, it will attempt to replace the current processes gem home and path with the one requested.

# File lib/rvm/environment/gemset.rb, line 82
def gemset_use(gemset, options = {})
  replace_env = options.delete(:replace_env)
  result = rvm(:gemset, :use, gemset, options)
  if result.successful?
    gemset_name = self.class.identifier_to_gemset_name(result[:GEM_HOME] || result[:rvm_env_string])
    @environment_name = self.class.environment_with_gemset(@environment_name, gemset_name)
    @expanded_name    = nil
    self.class.reset_current!
    use_env_from_result! result if replace_env
    true
  end
end
gemset_use!(name, options = {}) click to toggle source

Like #gemset_use, but replaces the env by default.

# File lib/rvm/environment/gemset.rb, line 96
def gemset_use!(name, options = {})
  gemset_use name, {:replace_env => true}.merge(options)
end
info(*ruby_strings) click to toggle source

Return a Hash with the same output that command:

$ rvm info

# File lib/rvm/environment/info.rb, line 10
def info(*ruby_strings)
  ruby_string = normalize_ruby_string(ruby_strings)
  res = rvm(:info, ruby_string)
  res.successful? ? YAML.load(res.stdout) : {}
end
inspect() click to toggle source
# File lib/rvm/environment.rb, line 32
def inspect
  "#<#{self.class.name} environment_name=#{@environment_name.inspect}>"
end
install(rubies, opts = {}) click to toggle source

Installs the given ruby

# File lib/rvm/environment/rubies.rb, line 5
def install(rubies, opts = {})
  rvm(:install, normalize_ruby_string(rubies), opts).successful?
end
list() click to toggle source

Returns an interface to a more Ruby-like interface for list.

# File lib/rvm/environment/list.rb, line 49
def list
  @list_helper ||= ListWrapper.new(self)
end
list_default() click to toggle source

Lists the default ruby (minus gemset) Suppose that Ruby 1.9.2 patchlevel 0, is the default:

env.list_default # => “ruby-1.9.2-p0”

# File lib/rvm/environment/list.rb, line 25
def list_default
  normalize rvm(:list, :default, :string).stdout
end
list_gemsets() click to toggle source

Returns a raw array list of ruby + gemset combinations.

env.list_gemsets # => ['ruby-1.9.2-p0@my_gemset', 'jruby@my_gemset', …]

# File lib/rvm/environment/list.rb, line 8
def list_gemsets
  normalize_listing_output rvm(:list, :gemsets, :strings).stdout
end
list_known() click to toggle source

Lists all known ruby strings (raw, filtered output)

# File lib/rvm/environment/list.rb, line 31
def list_known
  normalize_listing_output rvm(:list, :known).stdout
end
list_known_strings() click to toggle source

Lists all known ruby strings

# File lib/rvm/environment/list.rb, line 37
def list_known_strings
  normalize_listing_output rvm(:list, :known_strings).stdout
end
list_ruby_svn_tags() click to toggle source

Lists all known svn tags.

# File lib/rvm/environment/list.rb, line 43
def list_ruby_svn_tags
  normalize_listing_output rvm(:list, :ruby_svn_tags).stdout
end
list_strings() click to toggle source

Returns a raw array list of installed ruby strings, including aliases.

env.list_strings # => [“ruby-1.9.2-p0”, “jruby-1.5.3”]

# File lib/rvm/environment/list.rb, line 16
def list_strings
  normalize_listing_output rvm(:list, :strings).stdout.tr(' ', "\n")
end
path_for(command) click to toggle source

Returns the path for the given command

Suppose that you are in the 1.9.2 environment.

env.path_for(:rspec) # => '~/.rvm/gems/ruby-1.9.2-p0/bin/rspec' env.path_for(:ruby) # => '~/.rvm/rubies/ruby-1.9.2-p0/bin/ruby'

# File lib/rvm/environment/env.rb, line 33
def path_for(command)
  run(:command, "-v", command).stdout.strip
end
Also aliased as: which
rake(file = nil, options = {}) click to toggle source

Execute rake (optionally taking the path to a rake file), then change back.

# File lib/rvm/environment/sets.rb, line 31
def rake(file = nil, options = {})
  if file.nil?
    perform_set_operation :rake, options
  else
    file = File.expand_path(file)
    chdir(File.dirname(file)) do
      perform_set_operation(:rake, options.merge(:rakefile => file))
    end
  end
end
remove(rubies, opts = {}) click to toggle source

Removes a given ruby from being managed by rvm.

# File lib/rvm/environment/rubies.rb, line 15
def remove(rubies, opts = {})
  rvm(:remove, normalize_ruby_string(rubies), opts).successful?
end
ruby(runnable, options = {}) click to toggle source

Passed either something containing ruby code or a path to a ruby file, will attempt to exectute it in the current environment.

# File lib/rvm/environment/sets.rb, line 7
def ruby(runnable, options = {})
  if runnable.respond_to?(:path)
    # Call the path
    ruby_run runnable.path, options
  elsif runnable.respond_to?(:to_str)
    runnable = runnable.to_str
    File.exist?(runnable) ? ruby_run(runnable, options) : ruby_eval(runnable, options)
  elsif runnable.respond_to?(:read)
    ruby_run runnable.read
  end
end
ruby_eval(code, options = {}) click to toggle source

Eval the given code within ruby.

# File lib/rvm/environment/sets.rb, line 20
def ruby_eval(code, options = {})
  perform_set_operation :ruby, "-e", code.to_s, options
end
ruby_run(path, options = {}) click to toggle source

Run the given path as a ruby script.

# File lib/rvm/environment/sets.rb, line 25
def ruby_run(path, options = {})
  perform_set_operation :ruby, path.to_s, options
end
rvm(*args) click to toggle source

Lets you build a command up, without needing to see the output. As an example,

rvm :use, "ree@rails3", :install => true

Will call the following:

rvm use ree@rails3 --install
# File lib/rvm/environment/utility.rb, line 61
def rvm(*args)
  options = extract_options!(args)
  silent = options.delete(:silent)
  rearrange_options!(args, options)
  args += hash_to_options(options)
  args.map! { |a| a.to_s }

  if silent
    run_silently('rvm', *args)
  else
    run('rvm', *args)
  end
end
specs(options = {}) click to toggle source

Use the rvm spec runner for specs.

# File lib/rvm/environment/sets.rb, line 48
def specs(options = {})
  perform_set_operation :specs, options
end
system(command, *args) click to toggle source

Like Kernel.system, but evaluates it within the environment. Also note that it doesn't support redirection etc.

# File lib/rvm/environment/sets.rb, line 54
def system(command, *args)
  identifier = extract_identifier!(args)
  args = [identifier, :exec, command, *args].compact
  rvm(*args).successful?
end
tests(options = {}) click to toggle source

Use the rvm test runner for unit tests.

# File lib/rvm/environment/sets.rb, line 43
def tests(options = {})
  perform_set_operation :tests, options
end
tools() click to toggle source

Return the tools wrapper.

# File lib/rvm/environment/tools.rb, line 34
def tools
  @tools_wrapper ||= ToolsWrapper.new(self)
end
tools_identifier() click to toggle source

Gets the full name for the current env.

# File lib/rvm/environment/tools.rb, line 5
def tools_identifier
  normalize rvm(:tools, :identifier).stdout
end
tools_path_identifier(path) click to toggle source

Gets the identifier after cd'ing to a path, no destructive.

# File lib/rvm/environment/tools.rb, line 10
def tools_path_identifier(path)
  path_identifier = rvm(:tools, "path-identifier", path.to_s)
  if path_identifier.exit_status == 2
    error_message = "The rvmrc located in '#{path}' could not be loaded, likely due to trust mechanisms."
    error_message << " Please run 'rvm rvmrc {trust,untrust} \"#{path}\"' to continue, or set rvm_trust_rvmrcs_flag to 1."
    raise ErrorLoadingRVMRC, error_message
  end
  return normalize(path_identifier.stdout)
end
tools_strings(*rubies) click to toggle source
# File lib/rvm/environment/tools.rb, line 20
def tools_strings(*rubies)
  rubies = rubies.flatten.join(",").split(",").uniq
  names = {}
  value = rvm(:tools, :strings, *rubies)
  if value.successful?
    parts = value.stdout.split
    rubies.each_with_index do |key, index|
      names[key] = normalize(parts[index])
    end
  end
  names
end
uninstall(rubies, opts = {}) click to toggle source

Uninstalls a ruby (remove but keeps src etc)

# File lib/rvm/environment/rubies.rb, line 10
def uninstall(rubies, opts = {})
  rvm(:uninstall, normalize_ruby_string(rubies), opts).successful?
end
use(ruby_string, opts = {}) click to toggle source

Changes the ruby string for the current environment.

env.use '1.9.2' # => nil env.use 'ree' # => nil

# File lib/rvm/environment/rubies.rb, line 24
def use(ruby_string, opts = {})
  ruby_string = ruby_string.to_s
  result = rvm(:use, ruby_string)
  if result.successful?
    @environment_name = ruby_string
    @expanded_name    = nil
    use_env_from_result! result if opts[:replace_env]
  end
end
use!(ruby_string, opts = {}) click to toggle source

Like use but with :replace_env defaulting to true.

# File lib/rvm/environment/rubies.rb, line 35
def use!(ruby_string, opts = {})
  use ruby_string, opts.merge(:replace_env => true)
end
use_from_path!(path) click to toggle source

Will get the ruby from the given path. If there is a compatible ruby found, it will then attempt to use the associated gemset. e.g. ::current.use_from_path! Dir.pwd

# File lib/rvm/environment/rubies.rb, line 43
def use_from_path!(path)
 use! tools.path_identifier(path)
end
which(command)
Alias for: path_for
wrapper(ruby_string, wrapper_prefix, *binaries) click to toggle source

Generates wrappers with the specified prefix, pointing to ruby_string.

# File lib/rvm/environment/wrapper.rb, line 6
def wrapper(ruby_string, wrapper_prefix, *binaries)
  rvm(:wrapper, ruby_string, wrapper_prefix, *binaries).successful?
end
wrapper_path_for(executable) click to toggle source

If available, return the path to the wrapper for the given executable. Will return ni if the wrapper is unavailable.

# File lib/rvm/environment/wrapper.rb, line 18
def wrapper_path_for(executable)
  raise NotImplementedError
end

Protected Instance Methods

compatible_with_current?(result) click to toggle source

Checks whether the given environment is compatible with the current ruby interpeter.

# File lib/rvm/environment/utility.rb, line 108
def compatible_with_current?(result)
  ruby_string(result) == self.class.current_ruby_string
end
extract_environment!(options) click to toggle source

From an options hash, extract the environment identifier.

# File lib/rvm/environment/sets.rb, line 89
def extract_environment!(options)
  values = []
  [:environment, :env, :rubies, :ruby].each do |k|
    values << options.delete(k)
  end
  values.compact.first
end
extract_identifier!(args) click to toggle source

Shorthand to extra an identifier from args. Since we

# File lib/rvm/environment/sets.rb, line 99
def extract_identifier!(args)
  options = extract_options!(args)
  identifier = normalize_set_identifier(extract_environment!(options))
  args << options
  identifier
end
extract_options!(args) click to toggle source

Extract options from a hash.

# File lib/rvm/environment/utility.rb, line 133
def extract_options!(args)
  args.last.is_a?(Hash) ? args.pop : {}
end
hash_to_options(options) click to toggle source

Converts a hash of options to an array of command line argumets. If the value is false, it wont be added but if it is true only the key will be added. Lastly, when the value is neither true or false, to_s will becalled on it and it shall be added to the array.

# File lib/rvm/environment/utility.rb, line 141
def hash_to_options(options)
  result = []
  options.each_pair do |key, value|
    real_key = "--#{key.to_s.gsub("_", "-")}"
    if value == true
      result << real_key
    elsif value != false
      result << real_key
      result << value.to_s
    end
  end
  result
end
normalize(value) click to toggle source

Returns a value, or nil if it is blank.

# File lib/rvm/environment/utility.rb, line 122
def normalize(value)
  value = value.to_s.strip
  value.empty? ? nil : value
end
normalize_array(value) click to toggle source

Normalizes an array, removing blank lines.

# File lib/rvm/environment/utility.rb, line 128
def normalize_array(value)
  value.split("\n").map { |line| line.strip }.reject { |line| line.empty? }
end
normalize_listing_output(results) click to toggle source

Takes a list of rubies / items, 1 per line and strips comments and blank lines.

# File lib/rvm/environment/list.rb, line 129
def normalize_listing_output(results)
  lines = []
  results.each_line do |line|
    line = line.gsub(/#.*/, '').strip
    lines << line unless line.empty?
  end
  lines.sort
end
normalize_option_value(value) click to toggle source

Recursively normalize options.

# File lib/rvm/environment/utility.rb, line 156
def normalize_option_value(value)
  case value
  when Array
    value.map { |option| normalize_option_value(option) }.join(",")
  else
    value.to_s
  end
end
normalize_ruby_string(rubies) click to toggle source
# File lib/rvm/environment/rubies.rb, line 49
def normalize_ruby_string(rubies)
  Array(rubies).join(",")
end
normalize_set_identifier(identifier) click to toggle source

Converts the given identifier to a rvm-friendly form. Unlike using sets directly, a nil identifier is set to mean the current ruby (not all). :all or “all” will instead return the a blank identifier / run it against all rubies.

# File lib/rvm/environment/sets.rb, line 75
def normalize_set_identifier(identifier)
  case identifier
  when nil, ""
    @environment_name
  when :all, "all"
    nil
  when Array
    identifier.map { |i| normalize_set_identifier(i) }.uniq.join(",")
  else
    identifier.to_s
  end
end
perform_set_operation(*args) click to toggle source

Performs a set operation. If the :env or :environment option is given, it will return a yaml summary (instead of the stdout / stderr etc via a Result object.

# File lib/rvm/environment/sets.rb, line 109
def perform_set_operation(*args)
  options     = extract_options!(args)
  environment = extract_environment!(options)
  identifier  = normalize_set_identifier(environment)
  # Uses yaml when we have multiple identifiers.
  uses_yaml   = !environment.nil?
  options.merge!(:yaml => true) if uses_yaml
  args.unshift(identifier) unless identifier.nil?
  args << options
  result = rvm(*args)
  uses_yaml ? YAML.load(result.stdout) : result
end
rearrange_options!(args, options) click to toggle source

Moves certain options (e.g. yaml, json etc) to the front of the arguments list, making stuff like sets work.

# File lib/rvm/environment/utility.rb, line 87
def rearrange_options!(args, options)
  prefix_options = {}
  (PREFIX_OPTIONS + PREFIX_OPTIONS.map { |o| o.to_s }).each do |k|
    if options.has_key?(k)
      value = options.delete(k)
      prefix_options[k.to_sym] = value
    end
  end
  hash_to_options(prefix_options).reverse.each { |o| args.unshift(o) }
end
ruby_string(result) click to toggle source
# File lib/rvm/environment/utility.rb, line 98
def ruby_string(result)
  if result && result[:rvm_env_string]
    Environment.identifier_to_ruby_string result[:rvm_env_string]
  else
    self.class.identifier_to_ruby_string(expanded_name)
  end
end
source_rvm_environment() click to toggle source

Automatically load rvm config from the multiple sources.

# File lib/rvm/environment.rb, line 53
def source_rvm_environment
  rvm_path = config_value_for(:rvm_path, self.class.default_rvm_path, false)
  actual_config = defined_config.merge('rvm_path' => rvm_path)
  config = []
  actual_config.each_pair do |k, v|
    config << "#{k}=#{escape_argument(v.to_s)}"
  end
  run_silently "export #{config.join(" ")}"
  run_silently :source, File.join(rvm_path, "scripts", "rvm")
end
use_env_from_result!(result) click to toggle source
# File lib/rvm/environment/utility.rb, line 165
def use_env_from_result!(result)
  if compatible_with_current?(result)
    ENV['GEM_HOME']    = result[:GEM_HOME]
    ENV['GEM_PATH']    = result[:GEM_PATH]
    Gem.clear_paths if defined?(Gem)
  else
    raise IncompatibleRubyError.new(result, "The given ruby environment requires #{ruby_string(result)} (versus #{self.class.current_ruby_string})")
  end
end
use_rvm_environment() click to toggle source
# File lib/rvm/environment.rb, line 64
def use_rvm_environment
  rvm :use, @environment_name, :silent => true
end