Class: Ramaze::GemSetup
Instance Method Summary collapse
- #gem(name, version = nil, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ GemSetup
constructor
A new instance of GemSetup.
-
#install_gem(name, options) ⇒ Object
tell rubygems to install a gem.
- #run(&block) ⇒ Object
-
#setup ⇒ Object
all gems defined, let’s try to load/install them.
-
#setup_gem(name, options) ⇒ Object
first try to activate, install and try to activate again if activation fails the first time.
-
#temp_argv(extconf) ⇒ Object
prepare ARGV for rubygems installer.
Constructor Details
#initialize(options = {}, &block) ⇒ GemSetup
Returns a new instance of GemSetup.
33 34 35 36 37 38 39 |
# File 'lib/ramaze/setup.rb', line 33 def initialize( = {}, &block) @gems = [] @options = .dup @verbose = @options.delete(:verbose) run(&block) end |
Instance Method Details
#gem(name, version = nil, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ramaze/setup.rb', line 47 def gem(name, version = nil, = {}) if version.respond_to?(:merge!) = version else [:version] = version end @gems << [name, ] end |
#install_gem(name, options) ⇒ Object
tell rubygems to install a gem
86 87 88 89 90 91 92 93 |
# File 'lib/ramaze/setup.rb', line 86 def install_gem(name, ) installer = Gem::DependencyInstaller.new() temp_argv([:extconf]) do log "Installing #{name}" installer.install(name, [:version]) end end |
#run(&block) ⇒ Object
41 42 43 44 45 |
# File 'lib/ramaze/setup.rb', line 41 def run(&block) return unless block_given? instance_eval(&block) setup end |
#setup ⇒ Object
all gems defined, let’s try to load/install them
58 59 60 61 62 63 64 65 |
# File 'lib/ramaze/setup.rb', line 58 def setup require 'rubygems' require 'rubygems/dependency_installer' @gems.each do |name, | setup_gem(name, ) end end |
#setup_gem(name, options) ⇒ Object
first try to activate, install and try to activate again if activation fails the first time
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ramaze/setup.rb', line 69 def setup_gem(name, ) version = [[:version]].compact lib_name = [:lib] || name log "activating #{name}" Gem.activate(name, *version) require(lib_name) rescue LoadError install_gem(name, ) Gem.activate(name, *version) require(lib_name) end |
#temp_argv(extconf) ⇒ Object
prepare ARGV for rubygems installer
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ramaze/setup.rb', line 96 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 |