これが私が最終的に得たものです-setenv
シェルスクリプトのRubyバージョン:
# Read application config
$hConf, $fConf = {}, File.expand_path("../config.rb", __FILE__)
$hConf = File.open($fConf) {|f| eval(f.read)} if File.exist? $fConf
# Application classpath
$: << ($hConf[:appRoot] || File.expand_path("../bin/app", __FILE__))
# Ruby libs
$lib = ($hConf[:rubyLib] || File.expand_path("../bin/lib", __FILE__))
($: << [$lib]).flatten! # lib is string or array, standardize
次に、このスクリプトが何よりも先に 1 回呼び出されることを確認する必要があり、個々のソース ファイルに触れる必要はありません。
外部(非gem)ライブラリの場所など、いくつかのオプションを設定ファイル内に入れました:
# Site- and server specific config - location of DB, tmp files etc.
{
:webRoot => "/srv/www/myapp/data",
:rubyLib => "/somewhere/lib",
:tmpDir => "/tmp/myapp"
}
これは私にとってはうまく機能しており、設定ファイルのパラメーターを変更するだけで、複数のプロジェクトで setenv スクリプトを再利用できます。シェル スクリプト、IMO よりもはるかに優れた代替手段です。