Skip to content

Commit

Permalink
Honor the RUBY_INSTALL_SRC_DIR and RUBY_INSTALL_RUBIES_DIR env va…
Browse files Browse the repository at this point in the history
…riables.
  • Loading branch information
postmodern committed May 1, 2022
1 parent c5b7f81 commit 43e837b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
8 changes: 8 additions & 0 deletions doc/man/ruby-install.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ Uninstall a Ruby version:
*~/.rubies/$ruby-$version*
Default non-root user installation directory.

## ENVIRONMENT

*RUBY_INSTALL_SRC_DIR*
Overrides the default source directory.

*RUBY_INSTALL_RUBIES_DIR*
Overrides the default installation directory.

## AUTHOR

Postmodern <postmodern.mod3@gmail.com>
Expand Down
12 changes: 11 additions & 1 deletion share/man/man1/ruby-install.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Generated by kramdown-man 0.1.7
.\" Generated by kramdown-man 0.1.8
.\" https://github.com/postmodern/kramdown-man#readme
.TH ruby-install 1 "Aug 2018" ruby-install "User Manuals"
.LP
Expand Down Expand Up @@ -265,6 +265,16 @@ Default root user installation directory\.
\fI\[ti]\[sl]\.rubies\[sl]\[Do]ruby\-\[Do]version\fP
Default non\-root user installation directory\.
.LP
.SH ENVIRONMENT
.LP
.TP
\fIRUBY\[ru]INSTALL\[ru]SRC\[ru]DIR\fP
Overrides the default source directory\.
.LP
.TP
\fIRUBY\[ru]INSTALL\[ru]RUBIES\[ru]DIR\fP
Overrides the default installation directory\.
.LP
.SH AUTHOR
.LP
.PP
Expand Down
8 changes: 4 additions & 4 deletions share/ruby-install/ruby-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ make_opts=()
system_dir="/usr/local"

if (( UID == 0 )); then
src_dir="$system_dir/src"
rubies_dir="/opt/rubies"
src_dir="${RUBY_INSTALL_SRC_DIR:-$system_dir/src}"
rubies_dir="${RUBY_INSTALL_RUBIES_DIR:-/opt/rubies}"
else
src_dir="$HOME/src"
rubies_dir="$HOME/.rubies"
src_dir="${RUBY_INSTALL_SRC_DIR:-$HOME/src}"
rubies_dir="${RUBY_INSTALL_RUBIES_DIR:-$HOME/.rubies}"
fi

source "$ruby_install_dir/logging.sh"
Expand Down
22 changes: 22 additions & 0 deletions test/ruby-install-tests/variables_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,26 @@ function test_rubies_dir()
fi
}

function test_src_dir_with_RUBY_INSTALL_SRC_DIR()
{
export RUBY_INSTALL_SRC_DIR="/path/to/src/dir"
. ./share/ruby-install/ruby-install.sh

assertEquals "did not set \$src_dir to \$RUBY_INSTALL_SRC_DIR" \
"$RUBY_INSTALL_SRC_DIR" "$src_dir"

unset RUBY_INSTALL_SRC_DIR
}

function test_rubies_dir_with_RUBY_INSTALL_SRC_DIR()
{
export RUBY_INSTALL_RUBIES_DIR="/path/to/rubies/dir"
. ./share/ruby-install/ruby-install.sh

assertEquals "did not set \$rubies_dir to \$RUBY_INSTALL_RUBIES_DIR" \
"$RUBY_INSTALL_RUBIES_DIR" "$rubies_dir"

unset RUBY_INSTALL_RUBIES_DIR
}

SHUNIT_PARENT=$0 . $SHUNIT2

0 comments on commit 43e837b

Please sign in to comment.