Module: Gem
- Defined in:
- lib/vmbuilder_plugins/gem.rb
Overview
Purpose
Gem is a Capistrano plugin module providing a set of methods that invoke the gem package manager.
Installs within Capistrano as the plugin gem.
Usage
require 'vmbuilder_plugins/gem'
Prefix all calls to the library with gem.
Constant Summary collapse
- GEM_INSTALL =
Default install command
-
doesn’t install documentation
-
installs all required dependencies automatically.
-
"gem install --no-rdoc --no-ri"
- GEM_UPDATE =
GEM_INSTALL.sub("install", "update")
Instance Method Summary collapse
-
#cleanup ⇒ Object
Removes old versions of gems from installation area.
-
#install(packages, version = nil) ⇒ Object
Installs the gems detailed in
packages
, selecting versionversion
if specified. -
#select(package, version = nil, platform = 'ruby') ⇒ Object
Auto selects a gem from a list and installs it.
-
#update_system ⇒ Object
Upgrade the gem system to the latest version.
-
#upgrade ⇒ Object
Updates all the installed gems to the latest version.
Instance Method Details
#cleanup ⇒ Object
Removes old versions of gems from installation area.
45 46 47 |
# File 'lib/vmbuilder_plugins/gem.rb', line 45 def cleanup send(run_method, "gem cleanup") end |
#install(packages, version = nil) ⇒ Object
Installs the gems detailed in packages
, selecting version version
if specified.
packages
can be a single string or an array of strings.
54 55 56 |
# File 'lib/vmbuilder_plugins/gem.rb', line 54 def install(packages, version=nil) send(run_method,"#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{packages.to_a.join(' ')}") end |
#select(package, version = nil, platform = 'ruby') ⇒ Object
Auto selects a gem from a list and installs it.
gem has no mechanism on the command line of disambiguating builds for different platforms, and instead asks the user. This method has the necessary conversation to select the version
relevant to platform
(or the one nearest the top of the list if you don’t specify version
).
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vmbuilder_plugins/gem.rb', line 64 def select(package, version=nil, platform='ruby') selections={} cmd="#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{package}" send run_method, cmd do |channel, stream, data| data.each_line do | line | case line when /\s(\d+).*\(#{platform}\)/ if selections[channel[:host]].nil? selections[channel[:host]]=$1.dup+"\n" logger.info "Selecting #$&", "#{stream} :: #{channel[:host]}" end when /\s\d+\./ # Discard other selections from data stream when /^>/ channel.send_data selections[channel[:host]] logger.debug line, "#{stream} :: #{channel[:host]}" else logger.info line, "#{stream} :: #{channel[:host]}" end end end end |
#update_system ⇒ Object
Upgrade the gem system to the latest version. Runs via sudo
34 35 36 |
# File 'lib/vmbuilder_plugins/gem.rb', line 34 def update_system send(run_method, "#{GEM_UPDATE} --system") end |
#upgrade ⇒ Object
Updates all the installed gems to the latest version. Runs via sudo. Don’t use this command if any of the gems require a version selection.
40 41 42 |
# File 'lib/vmbuilder_plugins/gem.rb', line 40 def upgrade send(run_method, GEM_UPDATE) end |