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, try_install = true) ⇒ 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.
32 33 34 35 36 37 38 |
# File 'lib/ramaze/setup.rb', line 32 def initialize( = {}, &block) @gems = [] = .dup @verbose = .delete(:verbose) run(&block) end |
Instance Method Details
#gem(name, version = nil, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/ramaze/setup.rb', line 46 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
79 80 81 82 83 84 85 86 |
# File 'lib/ramaze/setup.rb', line 79 def install_gem(name, ) installer = Gem::DependencyInstaller.new() temp_argv([:extconf]) do log "Installing #{name}" installer.install(name, [:version]) end end |
#run(&block) ⇒ Object
40 41 42 43 44 |
# File 'lib/ramaze/setup.rb', line 40 def run(&block) return unless block_given? instance_eval(&block) setup end |
#setup ⇒ Object
all gems defined, let’s try to load/install them
57 58 59 60 61 62 63 64 |
# File 'lib/ramaze/setup.rb', line 57 def setup require 'rubygems' require 'rubygems/dependency_installer' @gems.each do |name, | setup_gem(name, ) end end |
#setup_gem(name, options, try_install = true) ⇒ Object
first try to activate, install and try to activate again if activation fails the first time
68 69 70 71 72 73 74 75 76 |
# File 'lib/ramaze/setup.rb', line 68 def setup_gem(name, , try_install = true) log "activating #{name}" Gem.activate(name, *[[:version]].compact) require([:lib] || name) rescue LoadError => exception puts exception install_gem(name, ) if try_install setup_gem(name, , try_install = false) end |
#temp_argv(extconf) ⇒ Object
prepare ARGV for rubygems installer
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ramaze/setup.rb', line 89 def temp_argv(extconf) if extconf ||= [:extconf] old_argv = ARGV.clone ARGV.replace(extconf.split(' ')) end yield ensure ARGV.replace(old_argv) if extconf end |