Parent

Class Index [+]

Quicksearch

Ramaze::GemSetup

Class responsible for installing and loading all the gems.

@author Michael Fellinger (manveru) @since 19-05-2009

Public Class Methods

new(options = {}, &block) click to toggle source

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
45:     def initialize(options = {}, &block)
46:       @gems = []
47:       @options = options.dup
48:       @verbose = @options.delete(:verbose)
49: 
50:       run(&block)
51:     end

Public Instance Methods

gem(name, version = nil, options = {}) click to toggle source

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
80:     def gem(name, version = nil, options = {})
81:       if version.respond_to?(:merge!)
82:         options = version
83:       else
84:         options[:version] = version
85:       end
86: 
87:       @gems << [name, options]
88:     end
install_gem(name, options) click to toggle source

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
135:     def install_gem(name, options)
136:       installer = Gem::DependencyInstaller.new(options)
137: 
138:       temp_argv(options[:extconf]) do
139:         log "Installing gem #{name}"
140:         installer.install(name, options[:version])
141:       end
142:     end
run(&block) click to toggle source

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
61:     def run(&block)
62:       return unless block_given?
63:       instance_eval(&block)
64:       setup
65:     end
setup() click to toggle source

Tries to install all the gems.

@author Michael Fellinger (manveru) @since 19-05-2009

     # File lib/ramaze/setup.rb, line 96
 96:     def setup
 97:       require 'rubygems'
 98:       require 'rubygems/dependency_installer'
 99: 
100:       @gems.each do |name, options|
101:         setup_gem(name, options)
102:       end
103:     end
setup_gem(name, options) click to toggle source

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
114:     def setup_gem(name, options)
115:       version  = [options[:version]].compact
116:       lib_name = options[:lib] || name
117: 
118:       log "Activating gem #{name}"
119: 
120:       activate(name, lib_name, *version)
121:     # Gem not installed yet
122:     rescue Gem::LoadError
123:       install_gem(name, options)
124:       activate(name, lib_name, *version)
125:     end
temp_argv(extconf) click to toggle source

Prepare ARGV for rubygems installer

@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] extconf

     # File lib/ramaze/setup.rb, line 151
151:     def temp_argv(extconf)
152:       if extconf ||= @options[:extconf]
153:         old_argv = ARGV.clone
154:         ARGV.replace(extconf.split(' '))
155:       end
156: 
157:       yield
158: 
159:     ensure
160:       ARGV.replace(old_argv) if extconf
161:     end

Private Instance Methods

activate(name, lib_name, *requirements) click to toggle source

Activates a gem and requires it.

@author Yorick Peterse @author Lee Jarvis @since 20-08-2011 @param [String] name The name of the gem to activate. @param [String] lib_name The name of the gem as it should be required. @param [Array] requirements An array with additional requirements.

     # File lib/ramaze/setup.rb, line 175
175:     def activate(name, lib_name, *requirements)
176:       if Gem::Specification.respond_to?(:find_by_name)
177:         Gem::Specification.find_by_name(name, *requirements).activate
178:       else
179:         Gem.activate(name, *requirements)
180:       end
181: 
182:       require(lib_name)
183:     end
log(msg) click to toggle source

Writes the message to the logger.

@author Michael Fellinger (manveru) @since 19-05-2009 @param [String] msg The message to write to the logger.

     # File lib/ramaze/setup.rb, line 192
192:     def log(msg)
193:       return unless @verbose
194: 
195:       if defined?(Log)
196:         Log.info(msg)
197:       else
198:         puts(msg)
199:       end
200:     end
rubyforge() click to toggle source

Installs a gem from Rubyforge.

@author Michael Fellinger (manveru) @since 19-05-2009

     # File lib/ramaze/setup.rb, line 208
208:     def rubyforge; 'http://gems.rubyforge.org/' end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.