Slide 1

Slide 1 text

Rubygems From Whence

Slide 2

Slide 2 text

+ Where do gems come from? + Where are gems installed to? + How do gems get onto the load path?

Slide 3

Slide 3 text

+ RVM gemsets + rbenv gemsets + Bundler

Slide 4

Slide 4 text

Tim Uruski Developer [email protected]

Slide 5

Slide 5 text

Where do Gems Come From?

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

$ gem install hola

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

https://rubygems.org

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

.gemrc

Slide 16

Slide 16 text

--- :backtrace: false :bulk_threshold: 1000 :sources: - https://rubygems.org - http://localhost:8808 :update_sources: true :verbose: true

Slide 17

Slide 17 text

$ gem install hola --config custom.yml

Slide 18

Slide 18 text

local .gem

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Git source

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

$ gem install specific_install $ gem specific_install [email protected]:qrush/hola.git $ gem specific_install qrush/hola

Slide 24

Slide 24 text

Where are Gems installed to?

Slide 25

Slide 25 text

$ 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

Slide 26

Slide 26 text

$ gem install hola --install-dir ~/gems

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

GEM_HOME

Slide 29

Slide 29 text

$ GEM_HOME=~/gems gem install hola

Slide 30

Slide 30 text

$ export GEM_HOME=~/gems $ gem install hola

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

WARNING

Slide 33

Slide 33 text

How do Gems get onto the load path?

Slide 34

Slide 34 text

require 'hola'

Slide 35

Slide 35 text

$ 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

Slide 36

Slide 36 text

$ 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

Slide 37

Slide 37 text

GEM_PATH

Slide 38

Slide 38 text

WARNING

Slide 39

Slide 39 text

GEM_HOME GEM_PATH

Slide 40

Slide 40 text

RVM gemsets

Slide 41

Slide 41 text

.rvm ├── bin ├── ... ├── gemsets └── scripts ├── ... ├── selector ├── selector_gemset └── ...

Slide 42

Slide 42 text

# .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"

Slide 43

Slide 43 text

GEM_HOME

Slide 44

Slide 44 text

# .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}"

Slide 45

Slide 45 text

GEM_PATH

Slide 46

Slide 46 text

# .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

Slide 47

Slide 47 text

~/.rvm/environments

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

rbenv gemsets

Slide 50

Slide 50 text

rbenv-gemset ├── bin ├── etc │ └── rbenv.d │ ├── exec │ │ └── gemset.bash │ ├── rehash │ │ └── gemset.bash │ └── which │ └── gemset.bash └── libexec

Slide 51

Slide 51 text

# .rbenv-gemsets example default

Slide 52

Slide 52 text

GEM_HOME

Slide 53

Slide 53 text

# 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

Slide 54

Slide 54 text

$ 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

Slide 55

Slide 55 text

GEM_PATH

Slide 56

Slide 56 text

# 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

Slide 57

Slide 57 text

$ 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

Slide 58

Slide 58 text

WARNING

Slide 59

Slide 59 text

Bundler

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

$ bundle install --path vendor/bundle $ bundle config path vendor/bundle

Slide 62

Slide 62 text

GEM_HOME

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

GEM_PATH

Slide 65

Slide 65 text

# 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)

Slide 66

Slide 66 text

# lib/bundler/dependency.rb class Dependency < Gem::Dependency attr_reader :autorequire attr_reader :groups ... end

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

# 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

Slide 69

Slide 69 text

# lib/bundler/rubygems_integration.rb class RubygemsIntegration ... class << self attr_reader :rubygems end end

Slide 70

Slide 70 text

# 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 ...

Slide 71

Slide 71 text

Bundler is big.

Slide 72

Slide 72 text

Rubygems provides the backbone to many tools

Slide 73

Slide 73 text

Thank you