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
|
# File 'lib/tap.rb', line 20
def setup(options=self.options)
env = Env.new
app = App.new({}, :env => env)
app.set('app', app)
app.set('env', env)
App.current = app
def options.process(key, default=nil)
value = self[key] || default
if self[:debug] == 'true'
$stderr.puts(App::LOG_FORMAT % [' ', nil, key, value])
end
value && block_given? ? yield(value) : nil
end
if options[:debug] == 'true'
options.process(:ruby, "#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}-#{RUBY_VERSION} (#{RUBY_RELEASE_DATE})")
options.process(:tap, VERSION)
app.debug = true
app.verbose = true
app.logger.level = Logger::DEBUG
end
options.process(:gems) do |gems|
cache_dir = options[:tap_cache]
if cache_dir.to_s.strip.empty?
require 'tmpdir'
cache_dir = Dir.tmpdir
end
env.signal(:load).call Env::Cache.new(cache_dir, options[:debug]).select(gems)
end
options.process(:path) do |path|
Env::Path.split(path).each {|dir| env.auto(:dir => dir) }
end
options.process(:tapenv) do |tapenv_path|
env.signal(:load).call Env::Path.split(tapenv_path)
end
options.process(:taprc) do |taprc_path|
app.signal(:load).call Env::Path.split(taprc_path)
end
options.process(:tapfile) do |tapfile_path|
Env::Path.split(tapfile_path).each do |tapfile|
next unless File.file?(tapfile)
Declarations::Context.new(app, File.basename(tapfile)).instance_eval(File.read(tapfile), tapfile, 1)
end
end
app
end
|