Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From Whence Rubygems

F78e9e14b7a79742c7109b6d36e3fbd5?s=47 Tim Uruski
February 20, 2014

From Whence Rubygems

A talk about where Rubygems come from? How they make their way from the internet (and other places) and into our programs.

F78e9e14b7a79742c7109b6d36e3fbd5?s=128

Tim Uruski

February 20, 2014
Tweet

Transcript

  1. Rubygems From Whence

  2. + Where do gems come from? + Where are gems

    installed to? + How do gems get onto the load path?
  3. + RVM gemsets + rbenv gemsets + Bundler

  4. Tim Uruski Developer tim@PetroFeed.com

  5. Where do Gems Come From?

  6. When a developer and some code love each other very

    much...
  7. $ gem install hola

  8. Fetching: hola-0.1.3.gem (100%) Successfully installed hola-0.1.3 Parsing documentation for hola-0.1.3

    Installing ri documentation for hola-0.1.3 1 gem installed
  9. https://rubygems.org

  10. $ gem install hola --source http://localhost:8808

  11. $ gem sources --add http://localhost:8808

  12. https://gems.github.com https://gems.rubyforge.org https://gemcutter.org https://rubygems.org

  13. $ gem sources --remove https://rubygems.org $ gem sources --add http://ruby.taobao.org

  14. $ gem sources *** CURRENT SOURCES *** https://rubygems.org http://localhost:8808

  15. .gemrc

  16. --- :backtrace: false :bulk_threshold: 1000 :sources: - https://rubygems.org - http://localhost:8808

    :update_sources: true :verbose: true
  17. $ gem install hola --config custom.yml

  18. local .gem

  19. $ gem install hola.gem $ gem install /path/to/hola.gem

  20. $ rake install hola $ gem install hola-0.1.3.gem

  21. Git source

  22. rubygems/lib/rubygems/source/git.rb # A git gem for use in a gem

    dependencies file.
  23. $ gem install specific_install $ gem specific_install git@github.com:qrush/hola.git $ gem

    specific_install qrush/hola
  24. Where are Gems installed to?

  25. $ gem env home > /home/timuruski/.gem/ruby/2.0 > /usr/lib/ruby/gems/2.0 ! $

    ruby -e "puts Gem.dir" > /home/timuruski/.gem/ruby/2.0 > /usr/lib/ruby/gems/2.0
  26. $ gem install hola --install-dir ~/gems

  27. gems ├── build_info ├── cache │ └── hola-0.1.3.gem ├── doc

    ├── extensions ├── gems │ └── hola-0.1.3 │ └── lib │ └── hola.rb └── specifications └── hola-0.1.3.gemspec
  28. GEM_HOME

  29. $ GEM_HOME=~/gems gem install hola

  30. $ export GEM_HOME=~/gems $ gem install hola

  31. $ export GEM_HOME=~/tmp $ gem install hola --install-dir ~/gems

  32. WARNING

  33. How do Gems get onto the load path?

  34. require 'hola'

  35. $ ruby -e "puts $:" > /usr/lib/ruby/2.0 ! $ ruby

    -e "require 'hola'; puts $:" > /usr/lib/ruby/gems/2.0/gems/hola-0.1.3/lib > /usr/lib/ruby/2.0
  36. $ gem env path > /usr/lib/ruby/gems/2.0 > /home/timuruski/.gem/ruby/2.0 ! $

    ruby -e "puts Gem.path" > /usr/lib/ruby/gems/2.0 > /home/timuruski/.gem/ruby/2.0
  37. GEM_PATH

  38. WARNING

  39. GEM_HOME GEM_PATH

  40. RVM gemsets

  41. .rvm ├── bin ├── ... ├── gemsets └── scripts ├──

    ... ├── selector ├── selector_gemset └── ...
  42. # .rvm/scripts/selector export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION IRBRC GEM_HOME="$rvm_ruby_gem_home" GEM_PATH="$rvm_ruby_gem_path"

  43. GEM_HOME

  44. # .rvm/scripts/selector_gemset rvm_ruby_gem_home= "${rvm_gems_path:-"$rvm_path/gems"}/ $rvm_ruby_string" rvm_ruby_gem_home= "${rvm_ruby_gem_home} ${rvm_gemset_separator:-"@"} ${rvm_gemset_name}"

  45. GEM_PATH

  46. # .rvm/scripts/selector_gemset if [[ "$rvm_gemset_name" == "global" ]] then rvm_ruby_gem_path="${rvm_ruby_gem_home}"

    else rvm_ruby_gem_path="${rvm_ruby_gem_home}:¶ ${rvm_ruby_global_gems_path}" fi
  47. ~/.rvm/environments

  48. echo " -->> ENVIRONMENT: $*" export PATH="/home/timuruski/.rvm/gems/ruby-2.0.0-p353@demo/bin:/home/timuruski/.rvm/gems/ ruby-2.0.0-p353@global/bin:/home/vagrant/.rvm/rubies/ruby-2.0.0-p353/bin:$PATH" export GEM_HOME='/home/timuruski/.rvm/gems/ruby-2.0.0-p353@demo'

    export GEM_PATH='/home/timuruski/.rvm/gems/ruby-2.0.0-p353@demo:/home/vagrant/.rvm/gems/ ruby-2.0.0-p353@global' export MY_RUBY_HOME='/home/timuruski/.rvm/rubies/ruby-2.0.0-p353' export IRBRC='/home/timuruski/.rvm/rubies/ruby-2.0.0-p353/.irbrc' unset MAGLEV_HOME unset RBXOPT
  49. rbenv gemsets

  50. rbenv-gemset ├── bin ├── etc │ └── rbenv.d │ ├──

    exec │ │ └── gemset.bash │ ├── rehash │ │ └── gemset.bash │ └── which │ └── gemset.bash └── libexec
  51. # .rbenv-gemsets example default

  52. GEM_HOME

  53. # rbenv-gemset/etc/rbenv.d/exec/gemset.bash unset GEM_HOME for gemset in $(rbenv-gemset active); do

    path="${RBENV_GEMSET_ROOT}/$gemset" if [ -z "$GEM_HOME" ]; then GEM_HOME="$path" fi done
  54. $ echo $GEM_HOME > ! $ gem env home >

    ~/.rbenv/versions/2.0.0/gemsets/example ! $ ruby -e "puts ENV['GEM_HOME']" > ~/.rbenv/versions/2.0.0/gemsets/example
  55. GEM_PATH

  56. # rbenv-gemset/etc/rbenv.d/exec/gemset.bash unset GEM_PATH for gemset in $(rbenv-gemset active); do

    path="${RBENV_GEMSET_ROOT}/$gemset" GEM_PATH="$GEM_PATH:$path" done
  57. $ echo $GEM_PATH > ! $ gem env path >

    ~/.rbenv/versions/2.0.0/gemsets/example > ~/.rbenv/versions/2.0.0/gemsets/default ! $ ruby -e "puts ENV['GEM_PATH']" > ~/.rbenv/versions/2.0.0/gemsets/example > ~/.rbenv/versions/2.0.0/gemsets/default
  58. WARNING

  59. Bundler

  60. lib ├── bundler │ ├── capistrano.rb │ ├── cli.rb │

    └── ... ├── ... └── bundler.rb
  61. $ bundle install --path vendor/bundle $ bundle config path vendor/bundle

  62. GEM_HOME

  63. # lib/bunder.rb ENV['GEM_HOME'] = File .expand_path(bundle_path, root) Bundler.rubygems.clear_paths

  64. GEM_PATH

  65. # lib/bundler.rb possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path] paths = possibles.flatten.compact.uniq .reject

    { |p| p.empty? } ENV["GEM_PATH"] = paths .join(File::PATH_SEPARATOR)
  66. # lib/bundler/dependency.rb class Dependency < Gem::Dependency attr_reader :autorequire attr_reader :groups

    ... end
  67. # lib/bundler/endpoint_specification.rb class EndpointSpecification < ¶ Gem::Specification include MatchPlatform end

  68. # lib/bundler/gem_installer.rb class GemInstaller < Gem::Installer def check_executable_overwrite(filename) # Bundler

    needs to install gems # regardless of binstub overwriting end end
  69. # lib/bundler/rubygems_integration.rb class RubygemsIntegration ... class << self attr_reader :rubygems

    end end
  70. # lib/bundler/rubygems_integration.rb if RubygemsIntegration.provides?(">= 1.99.99") @rubygems = RubygemsIntegration::Future.new elsif RubygemsIntegration.provides?('>=

    1.8.20') @rubygems = RubygemsIntegration::MoreModern.new elsif RubygemsIntegration.provides?('>= 1.8.5') @rubygems = RubygemsIntegration::Modern.new elsif RubygemsIntegration.provides?('>= 1.8.0') @rubygems = RubygemsIntegration::AlmostModern.new elsif ...
  71. Bundler is big.

  72. Rubygems provides the backbone to many tools

  73. Thank you