utility_rubygems 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. rubygems_detect_ruby_lib_gem_path_from()
  3. {
  4. ruby_lib_gem_path="$( __rvm_ruby_config_get ${1}prefix "$ruby_path" )" || ruby_lib_gem_path=""
  5. [[ -z "${ruby_lib_gem_path:-}" ]] ||
  6. {
  7. ruby_lib_gem_path="$( __rvm_ruby_config_get ${1}dir "$ruby_path" )" || ruby_lib_gem_path=""
  8. ruby_lib_gem_path="${ruby_lib_gem_path%/*}"
  9. }
  10. [[ -n "${ruby_lib_gem_path:-}" ]] || return 1
  11. [[ -d "${ruby_lib_gem_path}/gems" ]] || return 2
  12. }
  13. rubygems_detect_ruby_lib_gem_path_fallback()
  14. {
  15. rubygems_detect_ruby_lib_gem_path_from "rubylib" ||
  16. rubygems_detect_ruby_lib_gem_path_from "lib" ||
  17. return $?
  18. ruby_lib_gem_path+="/gems"
  19. \typeset ruby_version
  20. ruby_version="$( __rvm_ruby_config_get ruby_version "$ruby_path")" || ruby_version=""
  21. if
  22. [[ -n "${ruby_version:-}" && -d "${ruby_lib_gem_path}/${ruby_version:-}" ]]
  23. then
  24. ruby_lib_gem_path+="$ruby_version"
  25. elif
  26. [[ -d "${ruby_lib_gem_path}/shared" ]]
  27. then
  28. ruby_lib_gem_path+="shared"
  29. else
  30. return 3
  31. fi
  32. }
  33. rubygems_detect_ruby_lib_gem_path()
  34. {
  35. \typeset ruby_path
  36. ruby_path="$( __rvm_which "${1:-ruby}" )" ||
  37. {
  38. rvm_error "Missing 'ruby' in 'rubygems_detect_ruby_lib_gem_path'."
  39. return 1
  40. }
  41. ruby_lib_gem_path="$(
  42. unset GEM_HOME GEM_PATH
  43. "$ruby_path" -rrubygems -e 'puts Gem.default_dir' 2>/dev/null
  44. )" || ruby_lib_gem_path=""
  45. [[ -n "$ruby_lib_gem_path" ]] ||
  46. rubygems_detect_ruby_lib_gem_path_fallback ||
  47. return $?
  48. }