-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add command for communizing gems
- Loading branch information
1 parent
1361a9f
commit 2046b9a
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# shellcheck shell=bash | ||
|
||
# shellcheck source=lib/utils.sh | ||
source "$(dirname "${BASH_SOURCE[0]}")/../utils.sh" | ||
|
||
install_dir=$(asdf where ruby) | ||
install_dir="${install_dir%/*}" | ||
|
||
for version_dir in "$install_dir"/* | ||
do | ||
communize_gems "$version_dir" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# shellcheck shell=bash | ||
|
||
version="$1" | ||
|
||
# shellcheck source=lib/utils.sh | ||
source "$(dirname "${BASH_SOURCE[0]}")/../communize.bash" | ||
|
||
install_dir=$(asdf where ruby) | ||
|
||
if [[ -n "$version" ]] | ||
then | ||
install_dir="${install_dir%/*}/$version" | ||
fi | ||
|
||
communize_gems "$install_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#shellcheck shell=bash | ||
|
||
communize_gems(){ | ||
|
||
local install_path="$1" | ||
|
||
local version gem_dir etc_dir | ||
version=$(basename "$install_path") | ||
|
||
etc_dir="${install_path}/etc" | ||
communal_dir="${ASDF_DIR}/installs/rubygems" | ||
gem_dir="${communal_dir}/$( communize_version "$version")" | ||
individual_gem_dir="${install_path}/lib/ruby/gems" | ||
|
||
if [[ ! -d "$gem_dir" ]] | ||
then | ||
mkdir "$gem_dir" | ||
fi | ||
|
||
if [[ -L "$individual_gem_dir" ]] | ||
then | ||
echo "Gems for ruby ${version} already communized" | ||
elif [[ -d "$individual_gem_dir" ]] | ||
then | ||
rm -rf "$individual_gem_dir" | ||
fi | ||
if [[ ! -f "$individual_gem_dir" ]] | ||
then | ||
ln -s "$communal_dir" "$individual_gem_dir" | ||
fi | ||
|
||
if [[ ! -f "$etc_dir/gemrc" ]] | ||
then | ||
mkdir -p "$etc_dir" | ||
printf 'gemhome: %s\n' "$gem_dir" > "$etc_dir/gemrc" | ||
fi | ||
|
||
} | ||
|
||
communize_version(){ | ||
local version="$1" | ||
echo "${version%.*}.0" | ||
} |