/usr/lib/ruby/1.9.1/ramaze/setup.rb is in libramaze-ruby1.9.1 2010.06.18-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | module Ramaze
# Convenient setup and activation of gems from different sources and specific
# versions.
# It's almost like Kernel#gem but also installs automatically if a gem is
# missing.
#
# @example
#
# Ramaze.setup :verbose => true do
# # gem and specific version
# gem 'makura', '>=2009.01'
#
# # gem and name for require
# gem 'aws-s3', :lib => 'aws/s3'
#
# # gem with specific version from rubyforge (default)
# gem 'json', :version => '=1.1.3', :source => rubyforge
#
# # gem from github
# gem 'manveru-org', :lib => 'org', :source => github
# end
#
# @option options [boolean] (true) verbose
# @option options [String] (nil) extconf
# @yield block
# @see GemSetup#initialize
# @author manveru
def self.setup(options = {:verbose => true}, &block)
GemSetup.new(options, &block)
end
class GemSetup
def initialize(options = {}, &block)
@gems = []
@options = options.dup
@verbose = @options.delete(:verbose)
run(&block)
end
def run(&block)
return unless block_given?
instance_eval(&block)
setup
end
def gem(name, version = nil, options = {})
if version.respond_to?(:merge!)
options = version
else
options[:version] = version
end
@gems << [name, options]
end
# all gems defined, let's try to load/install them
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
def setup_gem(name, options)
version = [options[:version]].compact
lib_name = options[:lib] || name
log "activating #{name}"
Gem.activate(name, *version)
require(lib_name)
rescue LoadError
install_gem(name, options)
Gem.activate(name, *version)
require(lib_name)
end
# tell rubygems to install a gem
def install_gem(name, options)
installer = Gem::DependencyInstaller.new(options)
temp_argv(options[:extconf]) do
log "Installing #{name}"
installer.install(name, options[:version])
end
end
# prepare ARGV for rubygems installer
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
private
def log(msg)
return unless @verbose
if defined?(Log)
Log.info(msg)
else
puts(msg)
end
end
def rubyforge; 'http://gems.rubyforge.org/' end
def github; 'http://gems.github.com/' end
end
end
|