gemsets 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/base"
  3. source "$rvm_scripts_path/functions/build" # For gems with C extensions.
  4. gemset_list_all()
  5. {
  6. for rvm_ruby_string in $( __rvm_list_strings )
  7. do
  8. (__rvm_use ; gemset_list)
  9. done
  10. unset rvm_ruby_string
  11. }
  12. gemset_list_strings()
  13. {
  14. \typeset gem_string
  15. for rvm_ruby_string in $( __rvm_list_strings )
  16. do
  17. for gem_string in "${rvm_gems_path:-${rvm_path}/gems}/${rvm_ruby_string}" "${rvm_gems_path:-${rvm_path}/gems}/${rvm_ruby_string}${rvm_gemset_separator:-@}"*
  18. do
  19. printf "%b" "${gem_string##*/}\n"
  20. done
  21. done
  22. unset rvm_ruby_string
  23. }
  24. gemset_update()
  25. {
  26. if
  27. [[ -z "$rvm_ruby_strings" ]]
  28. then
  29. rvm_log "Running gem update for all rubies and gemsets."
  30. else
  31. rvm_log "Running gem update for the specified rubies."
  32. fi
  33. export rvm_ruby_strings="${rvm_ruby_strings:-all-gemsets}"
  34. export rvm_verbose_flag=1
  35. "$rvm_scripts_path/set" do gem update
  36. return $?
  37. }
  38. gemset_globalcache()
  39. {
  40. \typeset gc_status globalcache_enabled directories directory_name \
  41. full_directory_path directory_name
  42. if [[ "$1" == "enabled" ]]
  43. then
  44. if __rvm_using_gemset_globalcache
  45. then
  46. gc_status="Enabled"
  47. globalcache_enabled=0
  48. else
  49. gc_status="Disabled"
  50. globalcache_enabled=1
  51. fi
  52. rvm_log "Gemset global cache is currently: $gc_status"
  53. return $globalcache_enabled
  54. elif [[ "$1" == "disable" ]]
  55. then
  56. rvm_log "Removing the global cache (note: this will empty the caches)"
  57. __rvm_read_lines directories <(
  58. __rvm_cd "${rvm_gems_path:-"$rvm_path/gems"}" ;
  59. __rvm_find . -maxdepth 1 -mindepth 1 -type d -print | cut -c 3-
  60. )
  61. for directory_name in "${directories[@]//.\/}"
  62. do
  63. current_cache_path="${rvm_gems_path:-"$rvm_path/gems"}/$directory_name/cache"
  64. if [[ -L "$current_cache_path" \
  65. && "$(__rvm_readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]
  66. then
  67. rvm_log "Reverting the gem cache for $directory_name to an empty directory."
  68. \command \rm -f "$current_cache_path" 2>/dev/null
  69. mkdir -p "$current_cache_path" 2>/dev/null
  70. fi
  71. done
  72. __rvm_db_ "$rvm_user_path/db" "use_gemset_globalcache" "delete"
  73. elif [[ "$1" == "enable" ]]
  74. then
  75. rvm_log "Enabling global cache for gems."
  76. mkdir -p "$rvm_gems_cache_path"
  77. __rvm_read_lines directories <(
  78. __rvm_cd "${rvm_gems_path:-"$rvm_path/gems"}" ;
  79. __rvm_find . -maxdepth 1 -mindepth 1 -type d -print | cut -c 3-
  80. )
  81. for directory_name in "${directories[@]//.\/}"
  82. do
  83. current_cache_path="${rvm_gems_path:-"$rvm_path/gems"}/$directory_name/cache"
  84. if [[ -d "$current_cache_path" && ! -L "$current_cache_path" ]]
  85. then
  86. rvm_log "Moving the gem cache for $directory_name to the global cache."
  87. \command \mv "$current_cache_path/"*.gem "$rvm_gems_cache_path/" 2>/dev/null
  88. case "${current_cache_path%\/}" in
  89. *cache)
  90. __rvm_rm_rf "$current_cache_path"
  91. ln -fs "$rvm_gems_cache_path" "$current_cache_path"
  92. ;;
  93. esac
  94. fi
  95. done
  96. __rvm_db_ "$rvm_user_path/db" "use_gemset_globalcache" "true"
  97. else
  98. printf "%b" "
  99. Usage:
  100. rvm gemset globalcache {enable,disable,enabled}
  101. Enable / Disable / Status the use of a global gem cachedir.
  102. "
  103. return 1
  104. fi
  105. }
  106. gemset_name()
  107. {
  108. echo "${rvm_ruby_gem_home##*${rvm_gemset_separator:-"@"}}"
  109. return $?
  110. }
  111. gemset_dir()
  112. {
  113. echo "$rvm_ruby_gem_home"
  114. return $?
  115. }
  116. __gemset_list_single()
  117. {
  118. \typeset gemset current_gemset ruby_name default_name
  119. gemset="$1"
  120. current_gemset="$2"
  121. gemset="${gemset##*/}"
  122. ruby_name="${gemset%%${rvm_gemset_separator:-@}*}"
  123. gemset="${gemset#${ruby_name}}"
  124. gemset="${gemset#${rvm_gemset_separator:-@}}"
  125. if [[ "${_second_param}" == "strings" ]]
  126. then default_name="default"
  127. else default_name="(default)"
  128. fi
  129. [[ -n "${gemset}" ]] || gemset="$default_name"
  130. [[ -n "${current_gemset}" ]] || current_gemset="$default_name"
  131. if
  132. [[ "${gemset}" == "${current_gemset}" ]]
  133. then
  134. if [[ "${_second_param}" == "strings" ]]
  135. then echo "${gemset} #current"
  136. else echo "=> ${gemset}"
  137. fi
  138. else
  139. if [[ "${_second_param}" == "strings" ]]
  140. then echo "${gemset}"
  141. else echo " ${gemset}"
  142. fi
  143. fi
  144. }
  145. gemset_list()
  146. {
  147. [[ -d "${rvm_gems_path:-"$rvm_path/gems"}" ]] || {
  148. rvm_error "${rvm_gems_path:-"$rvm_path/gems"} does not exist!"
  149. return 1
  150. }
  151. [[ -n "${rvm_ruby_string:-""}" ]] || {
  152. rvm_error "\$rvm_ruby_string is not set!"
  153. return 1
  154. }
  155. \typeset current_gemset IFS
  156. current_gemset=$(__rvm_current_gemset)
  157. IFS=""
  158. [[ "${_second_param}" == "strings" ]] ||
  159. rvm_log "\ngemsets for $rvm_ruby_string (found in ${rvm_gems_path:-"$rvm_path/gems"}/$rvm_ruby_string)"
  160. for gemset in ${rvm_gems_path:-${rvm_path}/gems}/${rvm_ruby_string} ${rvm_gems_path:-${rvm_path}/gems}/${rvm_ruby_string}${rvm_gemset_separator:-@}*
  161. do
  162. __gemset_list_single "${gemset}" "${current_gemset}"
  163. done
  164. [[ "${_second_param}" == "strings" ]] || printf "%b" "\n"
  165. }
  166. gemset_delete_task()
  167. {
  168. \typeset rvm_gemset_name ruby_at_gemset gemdir
  169. rvm_gemset_name=$1
  170. ruby_at_gemset=$2
  171. gemdir=$3
  172. case ${_system_type} in
  173. (BSD)
  174. # will not find broken links
  175. __rvm_find "${rvm_bin_path:=$rvm_path/bin}" -name \*${ruby_at_gemset} -exec rm -rf '{}' \;
  176. __rvm_find -L "${rvm_bin_path:=$rvm_path/bin}" -name \*${ruby_at_gemset} -exec rm -rf '{}' \;
  177. ;;
  178. (*)
  179. __rvm_find "${rvm_bin_path:=$rvm_path/bin}" \( -name \*${ruby_at_gemset} -or -lname \*${ruby_at_gemset}/\* \) -delete
  180. ;;
  181. esac
  182. for item in $( $rvm_scripts_path/alias search_by_target ${ruby_at_gemset} )
  183. do
  184. $rvm_scripts_path/alias delete ${item}
  185. done
  186. __rvm_rm_rf "$gemdir" &&
  187. __rvm_rm_rf "${rvm_wrappers_path:="$rvm_path/wrappers"}/${ruby_at_gemset}" &&
  188. __rvm_rm_rf "${rvm_environments_path:="$rvm_path/environments"}/${ruby_at_gemset}"
  189. }
  190. gemset_delete()
  191. {
  192. [[ -n "${GEM_HOME:-}" ]] ||
  193. {
  194. rvm_error "A ruby must be selected in order to delete a gemset."
  195. return 1
  196. }
  197. if (( ${rvm_ruby_selected_flag:-0} == 0))
  198. then __rvm_ruby_string
  199. fi
  200. [[ -n "$rvm_gemset_name" ]] ||
  201. {
  202. rvm_error "A gemset name must be specified in order to delete a gemset."
  203. return 1
  204. }
  205. ruby_at_gemset="$rvm_ruby_string${rvm_gemset_separator:-"@"}$rvm_gemset_name"
  206. gemdir="${rvm_gems_path:-$rvm_path/gems}/${ruby_at_gemset}"
  207. [[ -e "$gemdir" ]] ||
  208. {
  209. rvm_warn "$gemdir did not previously exist. Ignoring."
  210. return 0
  211. }
  212. (( ${rvm_force_flag:-0} )) ||
  213. __rvm_ask_for "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?" yes ||
  214. {
  215. rvm_log "Not doing anything, phew... close call that one eh?"
  216. return 2
  217. }
  218. __rvm_log_command "gemset.delete" "Removing gemset $rvm_gemset_name" \
  219. gemset_delete_task "$rvm_gemset_name" "$ruby_at_gemset" "$gemdir"
  220. }
  221. gemset_empty()
  222. {
  223. \typeset gemdir entry
  224. if
  225. [[ -n "${GEM_HOME}" ]]
  226. then
  227. if
  228. [[ ${rvm_force_flag:-0} -gt 0 ]] ||
  229. __rvm_ask_for "Are you SURE you wish to remove the installed gems for ${GEM_HOME}?" yes
  230. then
  231. gem_install gem-empty &&
  232. \command \gem empty &&
  233. rvm_log "Removed successfully." ||
  234. return $?
  235. else
  236. rvm_log "Not doing anything, phew... close call that one eh?"
  237. return 2
  238. fi
  239. fi
  240. }
  241. # Migrate gemsets from ruby X to ruby Y
  242. gemset_copy()
  243. {
  244. \typeset source_ruby destination_ruby source_path destination_path
  245. # Clear the current environment so that it does not influence this operation.
  246. unset rvm_gemset_name rvm_ruby_gem_home GEM_HOME GEM_PATH
  247. source_ruby="${1:-}"
  248. destination_ruby="${2:-}"
  249. shift 2
  250. if
  251. [[ -z "$destination_ruby" || -z "$source_ruby" ]]
  252. then
  253. rvm_help gemset copy
  254. return 1
  255. fi
  256. # Verify the destination gemset exists before attempting to use it.
  257. (
  258. rvm_ruby_string="$destination_ruby"
  259. export rvm_create_flag=1
  260. { __rvm_ruby_string && __rvm_gemset_select; } 2> /dev/null
  261. ) ||
  262. {
  263. rvm_error "Destination gemset '$destination_ruby' does not yet exist."
  264. return 1
  265. }
  266. # TODO: Account for more possibilities:
  267. # rvm gemset copy 1.9.2 @gemsetb # From 1.9.2 default to current ruby, 1.9.2 exists.
  268. # rvm gemset copy @gemseta @gemsetb # Current ruby, gemseta exists.
  269. # rvm gemset copy gemseta gemsetb # Currently Ruby, gemseta exists.
  270. # rvm gemset copy gemseta 1.8.7@gemsetb # Currently Ruby@gemseta, current ruby@gemseta exists.
  271. source_path=$(
  272. __rvm_select "$source_ruby" > /dev/null 2>&1
  273. echo $rvm_ruby_gem_home
  274. )
  275. destination_path=$(
  276. __rvm_select "$destination_ruby" > /dev/null 2>&1
  277. echo $rvm_ruby_gem_home${rvm_expected_gemset_name:+@}${rvm_expected_gemset_name:-}
  278. )
  279. if
  280. [[ -z "$source_path" || ! -d "$source_path" ]]
  281. then
  282. rvm_error "Unable to expand '$source_ruby' or directory does not exist."
  283. return 1
  284. elif
  285. [[ -z "$destination_path" ]]
  286. then
  287. rvm_error "Unable to expand '$destination_ruby'."
  288. return 1
  289. fi
  290. if
  291. [[ -d "$source_path" ]]
  292. then
  293. rvm_log "Copying gemset from $source_ruby to $destination_ruby"
  294. for dir in "$source_path"/*
  295. do
  296. if
  297. [[ -d "$dir" ]]
  298. then
  299. __rvm_cp -Rf "$dir" "$destination_path/"
  300. elif
  301. [[ -L "$dir" ]]
  302. then
  303. __rvm_cp "$dir" "$destination_path/${dir##*/}"
  304. else
  305. rvm_debug "$dir not a file or link, not copying"
  306. fi
  307. done
  308. __rvm_log_command "gemset.wrappers" "Generating gemset wrappers ${destination_path##*/}" gemset_reset_env "${destination_path##*/}" &&
  309. __rvm_gemset_pristine "$destination_ruby"
  310. else
  311. rvm_error "Gems directory does not exist for $source_path ($source_path)"
  312. return 1
  313. fi
  314. }
  315. # Migrate gemsets from ruby X to ruby Y
  316. gemset_rename_()
  317. {
  318. \command \mv "$source_path" "$destination_path" &&
  319. \command \rm "${rvm_wrappers_path:="$rvm_path/wrappers"}/${source_path##*/}" &&
  320. \command \rm "${rvm_environments_path:="$rvm_path/environments"}/${source_path##*/}"
  321. }
  322. # Migrate gemsets from ruby X to ruby Y
  323. gemset_rename()
  324. {
  325. \typeset source_name destination_name source_path destination_path
  326. source_name="${1:-}"
  327. destination_name="${2:-""}"
  328. shift 2
  329. if
  330. [[ -z "$destination_name" || -z "$source_name" ]]
  331. then
  332. rvm_error "Source and destination gemsets must be specified: 'rvm gemset rename X Y'"
  333. return 1
  334. fi
  335. source_path="$(
  336. rvm_use_flag=0 rvm_silence_logging=1 rvm_gemset_name=${source_name} __rvm_use "${rvm_ruby_string}@${source_name}" 1>&2 ;
  337. gem env gemdir
  338. )"
  339. if
  340. [[ -z "$source_path" || ! -d "$source_path" ]]
  341. then
  342. rvm_error "gemset '$source_name' does not exist."
  343. return 2
  344. fi
  345. destination_path=${source_path/%$source_name/$destination_name}
  346. if
  347. [[ -d "$source_path" ]]
  348. then
  349. if
  350. [[ ! -d "$destination_path" ]]
  351. then
  352. __rvm_log_command "gemset.rename" "Renaming gemset ${source_path##*/} => ${destination_path##*/}" gemset_rename_ &&
  353. __rvm_log_command "gemset.reset" "Reseting gemset ${destination_path##*/}" gemset_reset_env "${destination_path##*/}" &&
  354. __rvm_gemset_pristine "${destination_path##*/}"
  355. else
  356. rvm_error "Gemset $destination_name already exists!"
  357. return 1
  358. fi
  359. else
  360. rvm_error "Gems directory does not exist for $source_path ($source_path)"
  361. return 1
  362. fi
  363. }
  364. gemset_unpack()
  365. {
  366. \typeset gems name directory version _platforms
  367. directory="${1:-vendor/gems}"
  368. if
  369. [[ -n "$rvm_ruby_gem_home" ]]
  370. then
  371. export GEM_HOME="$rvm_ruby_gem_home"
  372. export GEM_PATH="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"
  373. fi
  374. rvm_log "Unpacking current environments gemset to ${directory}\n"
  375. unset -f gem
  376. while read gem_name version _platforms
  377. do
  378. ( command gem unpack "$gem_name" -v"$version" --target "$directory" )&
  379. done <<<"$(
  380. GEM_PATH="$GEM_HOME" __rvm_list_gems
  381. )"
  382. wait
  383. rvm_log "Unpacking into ${directory} complete\n"
  384. return 0
  385. }
  386. gemset_export()
  387. {
  388. \typeset rvm_file_name gem_name version versions _platforms
  389. rvm_file_name="${1:-}"
  390. if
  391. [[ -n "$rvm_ruby_gem_home" ]]
  392. then
  393. export GEM_HOME="$rvm_ruby_gem_home"
  394. export GEM_PATH="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"
  395. fi
  396. if
  397. [[ -n "$rvm_file_name" ]]
  398. then
  399. [[ "${rvm_file_name}" == *Gemfile ]] || rvm_file_name="${rvm_file_name%.gems}.gems"
  400. else
  401. if [[ -n "$rvm_gemset_name" ]]
  402. then rvm_file_name="$rvm_gemset_name.gems"
  403. else rvm_file_name="default.gems"
  404. fi
  405. fi
  406. rvm_log "Exporting current environments gemset to $rvm_file_name"
  407. if [[ -f "$rvm_file_name" ]]
  408. then \command \rm -f "$rvm_file_name"
  409. fi
  410. if
  411. [[ "${rvm_file_name}" == *Gemfile ]]
  412. then
  413. printf "%b" "source 'https://rubygems.org'
  414. #ruby=${GEM_HOME##*/}
  415. "
  416. else
  417. printf "%b" "# $rvm_file_name generated gem export file. \
  418. Note that any env variable settings will be missing. \
  419. Append these after using a ';' field separator
  420. "
  421. fi > "$rvm_file_name"
  422. if
  423. (( ${rvm_latest_flag:-0} == 0 ))
  424. then
  425. while read gem_name version _platforms
  426. do
  427. if [[ "${rvm_file_name}" == *Gemfile ]]
  428. then echo "gem '$gem_name', '$version'"
  429. else echo "$gem_name -v$version"
  430. fi
  431. done <<<"$( GEM_PATH="$GEM_HOME" __rvm_list_gems )"
  432. else
  433. while read gem_name versions
  434. do
  435. if [[ "${rvm_file_name}" == *Gemfile ]]
  436. then echo "gem '$gem_name'"
  437. else echo "$gem_name"
  438. fi
  439. done <<<"$( GEM_PATH="$GEM_HOME" gem list )"
  440. fi >> "$rvm_file_name"
  441. }
  442. # Output the user's current gem directory.
  443. gemset_info()
  444. {
  445. if
  446. (( ${rvm_user_flag:-0} == 1 ))
  447. then
  448. (__rvm_use system ; gem env | __rvm_grep "\- $HOME" | __rvm_awk '{print $NF}')
  449. elif
  450. [[ ${rvm_system_flag:-0} == 1 ]]
  451. then
  452. (__rvm_use system ; gem env $action system)
  453. elif
  454. [[ -n "${rvm_ruby_string:-""}${rvm_gemset_name:+${rvm_gemset_separator:-"@"}}${rvm_gemset_name:-}" ]]
  455. then
  456. #TODO: why on ubuntu oneiric 32bit it's not enough to use gem env? why need to use again???
  457. (
  458. __rvm_use "${rvm_ruby_string:-""}${rvm_gemset_name:+${rvm_gemset_separator:-"@"}}${rvm_gemset_name:-}"
  459. gem env $action
  460. )
  461. else
  462. gem env $action
  463. fi
  464. return $?
  465. }
  466. gemset_prune()
  467. {
  468. \typeset temporary_cache_path live_cache_path gemset_name version versions cached_gem_name cached_file_path
  469. temporary_cache_path="$GEM_HOME/temporary-cache"
  470. live_cache_path="$GEM_HOME/cache"
  471. mkdir -p "$temporary_cache_path"
  472. rvm_log "Moving active gems into temporary cache..."
  473. while
  474. read gem_name version _platforms
  475. do
  476. cached_gem_name="${gem_name}-${version}.gem"
  477. cached_file_path="${live_cache_path}/${cached_gem_name}"
  478. if
  479. [[ -f "$cached_file_path" ]]
  480. then
  481. \command \mv "$cached_file_path" "${temporary_cache_path}/${cached_gem_name}"
  482. fi
  483. done <<<"$( GEM_PATH="$GEM_HOME" __rvm_list_gems )"
  484. rvm_log "Removing live cache and restoring temporary cache..."
  485. # Switch the cache back.
  486. __rvm_rm_rf "$live_cache_path"
  487. \command \mv "$temporary_cache_path" "$live_cache_path"
  488. return 0
  489. }
  490. gem_search()
  491. {
  492. \typeset gemspec gemspecs gem_name option environment_id ruby_string name gem_version
  493. gem_name="${1:-}"
  494. option="${2:-}"
  495. if [[ -z "${gem_name}" ]]
  496. then
  497. return 0
  498. fi
  499. true "${rvm_gems_path:="$rvm_path/gems"}"
  500. __rvm_read_lines gemspecs <(
  501. __rvm_find "${rvm_gems_path}" -mindepth 3 -iname "${gem_name}*.gemspec" -type f
  502. )
  503. if [[ "${option}" != "strings" ]]
  504. then
  505. printf "%-40s %-20s %-20s\n" "environment_id" "name" "version"
  506. printf "%b" "================================================================================\n"
  507. fi
  508. for gemspec in "${gemspecs[@]}"
  509. do
  510. environment_id="${gemspec//${rvm_gems_path}\/}"
  511. environment_id="${environment_id//\/*}"
  512. ruby_string="${environment_id//@*}"
  513. gemset_name="${environment_id//${ruby_string}}"
  514. name=${gemspec//*\/}
  515. name=${name/%.gemspec}
  516. gem_version=${name}
  517. name=${name%%-+([0-9\.])}
  518. gem_version=${gem_version#${name}-}
  519. if [[ "$name" == "$gem_version" ]]
  520. then gem_version=""
  521. fi
  522. if [[ "${option}" != "strings" ]]
  523. then
  524. printf "%-40s %-20s %-20s\n" "${environment_id}" "${name}" "${gem_version}"
  525. else
  526. printf "%b" "${environment_id}\n"
  527. fi
  528. done
  529. }
  530. action="$1"
  531. (( $# == 0 )) || shift
  532. export _second_param="${1:-}"
  533. export rvm_gemset_name="${1:-}"
  534. rvm_sticky_flag=1
  535. gemset_actions_with_gem=(
  536. gemdir gempath gemhome home path version export dump import
  537. load pristine copy install initial prune rename update unpack
  538. )
  539. if
  540. [[ " ${gemset_actions_with_gem[*]} " == *" $action "* ]] &&
  541. ! builtin command -v gem > /dev/null
  542. then
  543. rvm_error "'gem' was not found, cannot perform gem actions (Do you have an RVM ruby selected?)"
  544. exit 1
  545. fi
  546. if [[ " $* " == *" --force "* ]]
  547. then export rvm_force_flag=1
  548. fi
  549. if
  550. [[ -z "$rvm_ruby_string" && "${GEM_HOME:-""}" == "${rvm_path}"* ]]
  551. then
  552. rvm_ruby_string="${GEM_HOME##*/}"
  553. rvm_ruby_string="${rvm_ruby_string%%@*}"
  554. fi
  555. if
  556. [[ -z "$rvm_gemset_name" && "${GEM_HOME:-""}" == "${rvm_path}"* ]]
  557. then
  558. rvm_gemset_name="${GEM_HOME##*/}"
  559. rvm_gemset_name="${rvm_gemset_name#${rvm_gemset_name%%@*}}"
  560. rvm_gemset_name="${rvm_gemset_name#@}"
  561. fi
  562. rvm_ruby_gem_home="${rvm_ruby_gem_home:-$GEM_HOME}"
  563. if
  564. [[ ! -d "$rvm_ruby_gem_home" ]] &&
  565. builtin command -v gem > /dev/null 2>&1
  566. then
  567. rvm_ruby_gem_home="$(gem env home)"
  568. fi
  569. case "$action" in
  570. import|load)
  571. if
  572. [[ -z "${rvm_ruby_strings:-""}" ]]
  573. then
  574. gemset_import "Installing gems" "$1"
  575. else
  576. rubies=()
  577. __rvm_custom_separated_array rubies , "$rvm_ruby_strings"
  578. for rvm_ruby_string in "${rubies[@]}"
  579. do
  580. __rvm_with "$rvm_ruby_string" gemset_import "Installing gems" "$1"
  581. done
  582. fi
  583. ;;
  584. export|dump)
  585. gemset_export "$@"
  586. ;;
  587. empty)
  588. __rvm_use "${1:+@}${1:-${GEM_HOME##*/}}"
  589. gemset_$action "$@"
  590. ;;
  591. create|initial|list)
  592. __rvm_select
  593. rvm_gemset_name="${rvm_gemset_name:-${rvm_expected_gemset_name:-}}"
  594. gemset_$action "$@"
  595. ;;
  596. copy|delete|dir|globalcache|list_all|list_strings|pristine|prune|rename|update|unpack|reset_env)
  597. gemset_$action "$@"
  598. ;;
  599. name|string)
  600. gemset_name "$@"
  601. ;;
  602. strings)
  603. gemset_list "$@"
  604. ;;
  605. gemdir|gempath|gemhome|home|path|version)
  606. gemset_info "$@"
  607. ;;
  608. install|search)
  609. gem_$action "$@"
  610. ;;
  611. clear)
  612. rvm_error "'rvm gemset clear' has been deprecated. Please use 'rvm use @default' instead."
  613. ;;
  614. help)
  615. rvm_help gemset
  616. ;;
  617. *)
  618. rvm_error_help "Unknown subcommand '$action'" gemset
  619. exit 1
  620. ;;
  621. esac