Class responsible for installing and loading all the gems.
@author Michael Fellinger (manveru) @since 19-05-2009
Creates a new instance of the class and saves the parameters that were set.
@author Michael Fellinger (manveru) @since 19-05-2009 @param [Hash] options Hash containing various options to pass to the
GemSetup class.
@option options :verbose When set to true Ramaze will log
various actions such as messages about the installation process.
@yield block
# File lib/ramaze/setup.rb, line 45 def initialize(options = {}, &block) @gems = [] @options = options.dup @verbose = @options.delete(:verbose) run(&block) end
Adds the given gem to the list of required gems.
@example
gem('json', '>=1.5.1')
@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] name The name of the gem to load. @param [String] version The version of the gem. @param [Hash] options Additional options to use when loading the gem. @option options :lib The name to load the gem as.
# File lib/ramaze/setup.rb, line 80 def gem(name, version = nil, options = {}) if version.respond_to?(:merge!) options = version else options[:version] = version end @gems << [name, options] end
Tell Rubygems to install a gem.
@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] name The name of the gem to activate. @param [Hash] options The options to use for installing the gem.
# File lib/ramaze/setup.rb, line 135 def install_gem(name, options) installer = Gem::DependencyInstaller.new(options) temp_argv(options[:extconf]) do log "Installing gem #{name}" installer.install(name, options[:version]) end end
Executes the data inside the block, loading all the gems and optionally installing them.
@author Michael Fellinger (manveru) @since 19-05-2009 @param [Proc] block A block containing all the calls to gem().
# File lib/ramaze/setup.rb, line 61 def run(&block) return unless block_given? instance_eval(&block) setup end
Tries to install all the gems.
@author Michael Fellinger (manveru) @since 19-05-2009
# File lib/ramaze/setup.rb, line 96 def setup require 'rubygems' require 'rubygems/dependency_installer' @gems.each do |name, options| setup_gem(name, options) end end
First try to activate, install and try to activate again if activation fails the first time.
@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] name The name of the gem to activate. @param [Hash] options The options from GemSetup#initialize.
# File lib/ramaze/setup.rb, line 114 def setup_gem(name, options) version = [options[:version]].compact lib_name = options[:lib] || name log "Activating gem #{name}" activate(name, lib_name, *version) # Gem not installed yet rescue Gem::LoadError install_gem(name, options) activate(name, lib_name, *version) end
Prepare ARGV for rubygems installer
@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] extconf
# File lib/ramaze/setup.rb, line 151 def temp_argv(extconf) if extconf ||= @options[:extconf] old_argv = ARGV.clone ARGV.replace(extconf.split(' ')) end yield ensure ARGV.replace(old_argv) if extconf end
Generated with the Darkfish Rdoc Generator 2.