Skip to content

Commit

Permalink
feat: add command for communizing gems
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz-makandra committed Jan 4, 2024
1 parent 1361a9f commit 093e1de
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/commands/command-communize-all.bash
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
15 changes: 15 additions & 0 deletions lib/commands/command-communize.bash
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"
40 changes: 40 additions & 0 deletions lib/communize.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#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"
else
ln -s "$communal_dir" "$individual_gem_dir"
mkdir -p "$etc_dir"
if [[ ! -f "$etc_dir/gemrc" ]]
then
printf 'gemhome: %s\n' "$gem_dir" > "$etc_dir/gemrc"
fi
fi

}

communize_version(){
local version="$1"
echo "${version%.*}.0"
}

0 comments on commit 093e1de

Please sign in to comment.