Class: Gem::Micro::Installer

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/microgem/installer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#config, #ensure_dir, #log, #replace, #tmpdir

Constructor Details

#initialize(gem_spec) ⇒ Installer

Returns a new instance of Installer.



8
9
10
# File 'lib/microgem/installer.rb', line 8

def initialize(gem_spec)
  @gem_spec = gem_spec
end

Instance Attribute Details

#gem_specObject (readonly)

Returns the value of attribute gem_spec.



6
7
8
# File 'lib/microgem/installer.rb', line 6

def gem_spec
  @gem_spec
end

Instance Method Details

#create_bin_wrappers!Object

Creates the executables for this gem in the Ruby bin dir.



107
108
109
# File 'lib/microgem/installer.rb', line 107

def create_bin_wrappers!
  @gem_spec.executables.each { |bin| BinWrapperEmitter.new(@gem_spec.name, bin).create_bin_wrapper! }
end

#create_ruby_gemspec!Object

Creates the Ruby ‘.gemspec’ used by RubyGems to find a gem at ruby_gemspec_file.



101
102
103
104
# File 'lib/microgem/installer.rb', line 101

def create_ruby_gemspec!
  log(:debug, "Creating gem spec file `#{ruby_gemspec_file}'")
  File.open(ruby_gemspec_file, 'w') { |f| f << @gem_spec.to_ruby }
end

#data_dirObject

Returns the full path to the gems data directory in the temporary directory.

installer.data_dir # => "/path/to/tmp/microgem/rake-0.8.1/data"


37
38
39
# File 'lib/microgem/installer.rb', line 37

def data_dir
  File.join(work_dir, 'data')
end

#data_fileObject

Returns the full path to the gems data archive in the temporary directory.

installer.data_file # => "/path/to/tmp/microgem/rake-0.8.1/data.tar.gz"


45
46
47
# File 'lib/microgem/installer.rb', line 45

def data_file
  "#{data_dir}.tar.gz"
end

#downloadObject

Downloads the gem to gem_file.

Raises a Gem::Micro::Downloader::DownloadError if downloading fails.



80
81
82
# File 'lib/microgem/installer.rb', line 80

def download
  Downloader.get(url, gem_file)
end

#gem_cache_fileObject

Returns the full path to the RubyGems gem file cache directory.



65
66
67
68
# File 'lib/microgem/installer.rb', line 65

def gem_cache_file
  ensure_dir Config.cache_path
  File.join(Config.cache_path, @gem_spec.gem_filename)
end

#gem_fileObject

Returns the full path to the gem in the temporary directory.

installer.gem_file # => "/path/to/tmp/microgem/rake-0.8.1.gem"


29
30
31
# File 'lib/microgem/installer.rb', line 29

def gem_file
  File.join(tmpdir, @gem_spec.gem_filename)
end

#install!Object

Installs all dependencies and then the gem itself. Skips installation if after installing the dependencies the gem is already installed.

You can force the gem to be installed even if the gem is already installed by setting Config.force? to true.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/microgem/installer.rb', line 116

def install!
  install_dependencies!
  
  if !Config.force? && File.exist?(install_path)
    log(:debug, "Already installed `#{@gem_spec}'")
  else
    log(:info, "Installing `#{@gem_spec}'")
    download
    unpack
    
    load_full_spec!
    
    replace(data_dir, install_path)
    replace(gem_file, gem_cache_file)
    
    create_bin_wrappers!
    create_ruby_gemspec!
  end
end

#install_pathObject

Returns the path to where the gem should be installed.

installer.install_path # => "/usr/local/lib/ruby/gems/1.8/gems/rake-0.8.1"


73
74
75
# File 'lib/microgem/installer.rb', line 73

def install_path
  File.join(Config.gems_path, @gem_spec.gem_dirname)
end

#load_full_spec!Object

Loads the full metadata gemspec from the unpacked gem and returns the Gem::Specification instance.



94
95
96
97
# File 'lib/microgem/installer.rb', line 94

def load_full_spec!
  Unpacker.gzip()
  @gem_spec = YAML.load(File.read())
end

#metadata_archive_fileObject



53
54
55
# File 'lib/microgem/installer.rb', line 53

def 
  "#{}.gz"
end

#metadata_fileObject



49
50
51
# File 'lib/microgem/installer.rb', line 49

def 
  File.join(work_dir, 'metadata')
end

#ruby_gemspec_fileObject

Returns the full path to the gems Ruby ‘.gemspec’ file. This file is needed by RubyGems to find the gem.



59
60
61
62
# File 'lib/microgem/installer.rb', line 59

def ruby_gemspec_file
  ensure_dir Config.specifications_path
  File.join(Config.specifications_path, "#{@gem_spec.gem_dirname}.gemspec")
end

#unpackObject

Unpacks the gem to work_dir.

Raises a Gem::Micro::Installer::UnpackError if unpacking fails.



87
88
89
90
# File 'lib/microgem/installer.rb', line 87

def unpack
  Unpacker.tar(gem_file, work_dir, false)
  Unpacker.tar(data_file, data_dir, true)
end

#urlObject

Returns the download url for the gem.

installer.url # => "http://gems.rubyforge.org/gems/rake-0.8.1.gem"


15
16
17
# File 'lib/microgem/installer.rb', line 15

def url
  "http://#{File.join(@gem_spec.source.host, 'gems', @gem_spec.gem_filename)}"
end

#work_dirObject

Returns the full path to the temporary gem directory.

installer.work_dir # => "/path/to/tmp/microgem/rake-0.8.1"


22
23
24
# File 'lib/microgem/installer.rb', line 22

def work_dir
  File.join(tmpdir, @gem_spec.gem_dirname)
end