소스 검색

create hook: version-name

Expose a `version-name` hook.

It is invoked *after* the traditional `RBENV_VERSION` lookup. Which means hook scripts can interrogate `$RBENV_VERSION_FILE` and/or `$RBENV_VERSION` (or use the executables).

The hooks are then run, giving plugins a chance to alter `RBENV_VERSION`. Once the hooks have run, we now have (in `$RBENV_VERSION`) the actual version we want to use (or it's empty which defaults to `system` per normal). Lastly, the same logic remains for checking if the version exists, or trimming the `ruby-` prefix.

Prime example: the ruby-bundler-ruby-version plugin can select a ruby by using the `ruby` directive from the `Gemfile` if a local `.ruby-version` doesn't exist.
pull/653/head^2
Jason Karns 9 년 전
committed by Mislav Marohnić
부모
커밋
258e4413b1
2개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. +7
    -0
      libexec/rbenv-version-name
  2. +19
    -0
      test/version-name.bats

+ 7
- 0
libexec/rbenv-version-name 파일 보기

@ -8,6 +8,13 @@ if [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
fi
OLDIFS="$IFS"
IFS=$'\n' scripts=(`rbenv-hooks version-name`)
IFS="$OLDIFS"
for script in "${scripts[@]}"; do
source "$script"
done
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
echo "system"
exit

+ 19
- 0
test/version-name.bats 파일 보기

@ -2,6 +2,13 @@
load test_helper
export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d"
create_hook() {
mkdir -p "${RBENV_ROOT}/rbenv.d/version-name"
cat > "${RBENV_ROOT}/rbenv.d/version-name/$1" <<<"$2"
}
create_version() {
mkdir -p "${RBENV_ROOT}/versions/$1"
}
@ -22,6 +29,18 @@ setup() {
assert_success "system"
}
@test "RBENV_VERSION can be overridden by hook" {
create_version "1.8.7"
create_version "1.9.3"
RBENV_VERSION=1.8.7 run rbenv-version-name
assert_success "1.8.7"
create_hook test.bash "RBENV_VERSION=1.9.3"
RBENV_VERSION=1.8.7 run rbenv-version-name
assert_success "1.9.3"
}
@test "RBENV_VERSION has precedence over local" {
create_version "1.8.7"
create_version "1.9.3"

불러오는 중...
취소
저장