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")
- GEM_UNINSTALL =
"gem uninstall"
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.
-
#uninstall(packages, version = nil) ⇒ Object
Uninstalls the gems detailed in
packages
, selecting versionversion
if specified. -
#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.
46 47 48 |
# File 'lib/vmbuilder_plugins/gem.rb', line 46 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.
55 56 57 |
# File 'lib/vmbuilder_plugins/gem.rb', line 55 def install(packages, version=nil) send(run_method,"#{GEM_INSTALL} #{if version then '-v '+version.to_s end} #{Array(packages).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
).
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vmbuilder_plugins/gem.rb', line 83 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 |
#uninstall(packages, version = nil) ⇒ Object
Uninstalls the gems detailed in packages
, selecting version version
if specified.
packages
can be a single string or an array of strings.
64 65 66 |
# File 'lib/vmbuilder_plugins/gem.rb', line 64 def uninstall(packages, version=nil) send(run_method,"#{GEM_UNINSTALL} #{if version then '-v '+version.to_s end} #{Array(packages).join(' ')}") end |
#update_system ⇒ Object
Upgrade the gem system to the latest version. Runs via sudo
35 36 37 |
# File 'lib/vmbuilder_plugins/gem.rb', line 35 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.
41 42 43 |
# File 'lib/vmbuilder_plugins/gem.rb', line 41 def upgrade send(run_method, GEM_UPDATE) end |