utils/ruby.sh: avoid nested ifs
This commit is contained in:
parent
083f56fafe
commit
b4267d80e4
@ -1,4 +1,5 @@
|
|||||||
test-ruby () {
|
test-ruby () {
|
||||||
|
[[ ! -x $1 ]] && { echo "false"; return 1; }
|
||||||
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
|
"$1" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e \
|
||||||
"puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == \
|
"puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == \
|
||||||
Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null
|
Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)" 2>/dev/null
|
||||||
@ -12,8 +13,7 @@ setup-ruby-path() {
|
|||||||
# When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
|
# When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh)
|
||||||
# also needs to be changed.
|
# also needs to be changed.
|
||||||
local required_ruby_version="2.6"
|
local required_ruby_version="2.6"
|
||||||
local old_ruby_path
|
local old_ruby_path ruby_clean_path ruby_user_path
|
||||||
local old_ruby_usable
|
|
||||||
local advice="
|
local advice="
|
||||||
If there's no Homebrew Portable Ruby available for your processor:
|
If there's no Homebrew Portable Ruby available for your processor:
|
||||||
- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build)
|
- install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build)
|
||||||
@ -25,11 +25,7 @@ If there's no Homebrew Portable Ruby available for your processor:
|
|||||||
vendor_ruby_current_version="$vendor_dir/portable-ruby/current"
|
vendor_ruby_current_version="$vendor_dir/portable-ruby/current"
|
||||||
vendor_ruby_path="$vendor_ruby_current_version/bin/ruby"
|
vendor_ruby_path="$vendor_ruby_current_version/bin/ruby"
|
||||||
|
|
||||||
if [[ -n $HOMEBREW_RUBY_PATH ]]
|
[[ -n $HOMEBREW_RUBY_PATH ]] && old_ruby_path=$HOMEBREW_RUBY_PATH
|
||||||
then
|
|
||||||
old_ruby_path="$HOMEBREW_RUBY_PATH"
|
|
||||||
old_ruby_usable=$(test-ruby "$HOMEBREW_RUBY_PATH")
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset HOMEBREW_RUBY_PATH
|
unset HOMEBREW_RUBY_PATH
|
||||||
|
|
||||||
@ -56,20 +52,16 @@ If there's no Homebrew Portable Ruby available for your processor:
|
|||||||
then
|
then
|
||||||
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
|
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
|
||||||
else
|
else
|
||||||
HOMEBREW_RUBY_PATH=$(type -P ruby)
|
ruby_clean_path=$(type -P ruby)
|
||||||
if [[ $(test-ruby "$HOMEBREW_RUBY_PATH") != "true" ]]
|
ruby_user_path=$(PATH="$HOMEBREW_PATH" type -P ruby)
|
||||||
then
|
if [[ $(test-ruby "$old_ruby_path") == "true" ]]; then
|
||||||
HOMEBREW_RUBY_PATH=$(PATH="$HOMEBREW_PATH" type -P ruby)
|
HOMEBREW_RUBY_PATH=$old_ruby_path
|
||||||
if [[ $(test-ruby "$HOMEBREW_RUBY_PATH") != "true" ]]
|
elif [[ $(test-ruby "$ruby_clean_path") == "true" ]]; then
|
||||||
then
|
HOMEBREW_RUBY_PATH=$ruby_clean_path
|
||||||
if [[ $old_ruby_usable != true ]]
|
elif [[ $(test-ruby "$ruby_user_path") == "true" ]]; then
|
||||||
then
|
HOMEBREW_RUBY_PATH=$ruby_user_path
|
||||||
onoe "Failed to find usable Ruby $required_ruby_version!"
|
else
|
||||||
unset HOMEBREW_RUBY_PATH
|
onoe "Failed to find usable Ruby $required_ruby_version!"
|
||||||
else
|
|
||||||
HOMEBREW_RUBY_PATH="$old_ruby_path"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user