class Object

Public Class Methods

run(cmd, options={}, &block) click to toggle source
# File lib/rvm/capistrano/selector_mixed.rb, line 17
def run(cmd, options={}, &block)
  if options[:eof].nil? && !cmd.include?(sudo)
    options = options.merge(:eof => !block_given?)
  end
  shell = options[:shell]
  options[:shell] = false

  parallel(options) do |session|
    if shell.nil?
      session.when "in?(:#{fetch(:rvm_require_role,nil)})", command_with_shell(cmd, fetch(:rvm_shell)), &block
    end
    session.else command_with_shell(cmd, shell), &block
  end
end

Public Instance Methods

_cset(name, *args, &block) click to toggle source

Taken from the capistrano code.

# File lib/rvm/capistrano/helpers/_cset.rb, line 7
def _cset(name, *args, &block)
  unless exists?(name)
    set(name, *args, &block)
  end
end
need_root(options = {}) click to toggle source
# File lib/rvm/capistrano/helpers/rvm_if_sudo.rb, line 17
def need_root(options = {})
  return true if rvm_type == :root || rvm_type == :system
  return false unless rvm_type == :mixed # must be user installation

  # Finally deal with mixed installations.  Whether we need sudo
  # depends on what we're trying to do.
  # If rvm_user config variable contains :gemsets (say), and we're
  # operating on gemsets, then we don't need root.  However, the
  # most common use case for sudo is for installing rubies, so we
  # default to that to keep the code simpler.
  options[:subject_class] ||= :rubies

  # rvm is installed system-wide in mixed installations
  return true if options[:subject_class] == :rvm

  return ! rvm_user.include?(options[:subject_class])
end
quote_and_escape(text, quote = "'") click to toggle source
# File lib/rvm/capistrano/helpers/quote_and_escape.rb, line 4
def quote_and_escape(text, quote = "'")
  "#{quote}#{text.gsub(/#{quote}/) { |m| "#{quote}\\#{quote}#{quote}" }}#{quote}"
end
run_silent_curl(command, options={}) click to toggle source
# File lib/rvm/capistrano/helpers/run_silent_curl.rb, line 4
  def run_silent_curl(command, options={})
    run_without_rvm(<<-EOF.gsub(/[\s]+/, ' '))
      __LAST_STATUS=0;
      export CURL_HOME="${TMPDIR:-${HOME}}/.rvm-curl-config.$$";
      mkdir ${CURL_HOME}/;
      {
        [[ -r ${HOME}/.curlrc ]] && cat ${HOME}/.curlrc;
        echo "silent";
        echo "show-error";
      } > $CURL_HOME/.curlrc;
      #{command} || __LAST_STATUS=$?;
      rm -rf $CURL_HOME;
      exit ${__LAST_STATUS}
    EOF
  end
rvm_if_sudo(options = {}) click to toggle source
# File lib/rvm/capistrano/helpers/rvm_if_sudo.rb, line 10
def rvm_if_sudo(options = {})
  return '' unless need_root(options)
  prohibited = sudo_prohibited(options)
  return prohibited if prohibited # will cause a deferred error
  return "#{sudo} "
end
rvm_with_capistrano(&block) click to toggle source
# File lib/rvm/capistrano/helpers/base.rb, line 13
def rvm_with_capistrano(&block)
  if Capistrano.const_defined?(:Configuration) &&
      Capistrano::Configuration.methods.map(&:to_sym).include?(:instance)
    Capistrano::Configuration.instance(true).load(&block)
  end
end
sudo_prohibited(options = {}) click to toggle source
# File lib/rvm/capistrano/helpers/rvm_if_sudo.rb, line 35
  def sudo_prohibited(options = {})
    return false if fetch(:use_sudo, true) || rvm_install_with_sudo

    explanation = <<-EXPLANATION
You can enable use_sudo within rvm for use only by this install operation by adding to deploy.rb:

    set :rvm_install_with_sudo, true

    EXPLANATION

    if options[:deferred]
      <<-DEFERRED_ERROR.gsub(/\n/, " ; ")
echo "
Neither :use_sudo or :rvm_install_with_sudo was set and installation would ended up in using 'sudo'
#{explanation}
" >&2
exit 1
      DEFERRED_ERROR
    else
      raise "

:use_sudo is set to 'false' but sudo is needed to install rvm_type: #{rvm_type}.
#{explanation}
"
    end
  end
with_rvm_group(command, options = {}) click to toggle source
# File lib/rvm/capistrano/helpers/with_rvm_group.rb, line 7
  def with_rvm_group(command, options = {})
    if need_root(options)
      rvm_user_command + <<-CODE
if id | grep ' groups=.*(rvm)' >/dev/null ;
then #{command} ;
else #{rvm_if_sudo(options.merge(:deferred => true))} sg rvm -c #{quote_and_escape(command)} ;
fi
      CODE
    else
      command
    end
  end