Class: Gem::Micro::Installer
- Inherits:
-
Object
- Object
- Gem::Micro::Installer
- Includes:
- Utils
- Defined in:
- lib/microgem/installer.rb
Instance Attribute Summary collapse
-
#gem_spec ⇒ Object
readonly
Returns the value of attribute gem_spec.
Instance Method Summary collapse
-
#create_bin_wrappers! ⇒ Object
Creates the executables for this gem in the Ruby bin dir.
-
#create_ruby_gemspec! ⇒ Object
Creates the Ruby ‘.gemspec’ used by RubyGems to find a gem at ruby_gemspec_file.
-
#data_dir ⇒ Object
Returns the full path to the gems data directory in the temporary directory.
-
#data_file ⇒ Object
Returns the full path to the gems data archive in the temporary directory.
-
#download ⇒ Object
Downloads the gem to gem_file.
-
#gem_cache_file ⇒ Object
Returns the full path to the RubyGems gem file cache directory.
-
#gem_file ⇒ Object
Returns the full path to the gem in the temporary directory.
-
#initialize(gem_spec) ⇒ Installer
constructor
A new instance of Installer.
-
#install! ⇒ Object
Installs all dependencies and then the gem itself.
-
#install_path ⇒ Object
Returns the path to where the gem should be installed.
-
#load_full_spec! ⇒ Object
Loads the full metadata gemspec from the unpacked gem and returns the Gem::Specification instance.
- #metadata_archive_file ⇒ Object
- #metadata_file ⇒ Object
-
#ruby_gemspec_file ⇒ Object
Returns the full path to the gems Ruby ‘.gemspec’ file.
-
#unpack ⇒ Object
Unpacks the gem to work_dir.
-
#url ⇒ Object
Returns the download url for the gem.
-
#work_dir ⇒ Object
Returns the full path to the temporary gem directory.
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_spec ⇒ Object (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_dir ⇒ Object
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_file ⇒ Object
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 |
#download ⇒ Object
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_file ⇒ Object
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_file ⇒ Object
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_path ⇒ Object
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_file ⇒ Object
53 54 55 |
# File 'lib/microgem/installer.rb', line 53 def "#{}.gz" end |
#metadata_file ⇒ Object
49 50 51 |
# File 'lib/microgem/installer.rb', line 49 def File.join(work_dir, 'metadata') end |
#ruby_gemspec_file ⇒ Object
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 |
#unpack ⇒ Object
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 |
#url ⇒ Object
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_dir ⇒ Object
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 |