【发布时间】:2011-05-08 12:32:48
【问题描述】:
我尝试在我的 environment.rb 中为 rake 任务“gems:install”禁用插件的自动加载,因为它可能会导致未解决的依赖项和错误(阅读http://blog.joopp.com/2009/01/26/plugin-gem-dependencies-in-your-environmentrb/ 了解更多信息)。
在实现这个“hack”时,我很快注意到变量 $rails_gem_installer,如果 gems:install 运行,应该设置为 true,没有设置。 (==无)
现在我正在寻找一种方法来获取有关被调用的 rake 任务的信息,或者是否有其他可行的解决方案?
我正在运行 Rails 2.3.10 / Ruby 1.8.7
这是我的 environment.rb 中的代码,以便更好地理解:
Rails::Initializer.run do |config|
# fix for plugins dependent on gems
# see http://blog.joopp.com/2009/01/26/plugin-gem-dependencies-in-your-environmentrb/
if $rails_gem_installer
# We stop the initializer to load the files from the /config/initializers dir. This is to disable the usage of plugins or gems in that code.
puts 'Disabling the application initializers (rails_gem_installer == true)'
class Rails::Initializer
def load_application_initializers; end
end
# Next, do _only_ load the needed plugins that are not dependent on gems. For example exception_notification since that one is used in application.rb.
puts 'Not loading all plugins (rails_gem_installer == true)'
config.plugins = [:exception_notification]
else
# Otherwise, when we're just loading the environment.. load everything in the right order. So this is YOUR config.plugins = [something]!
config.plugins = [:all]
end
[... stuff like config.gem and so on]
【问题讨论】:
-
我不确定您要做什么。但是如果你需要像这样破解默认的 Rails 行为,你可能做错了。
-
如果您曾经遇到过插件(供应商/插件)依赖于 gem 的情况,您可能会理解这个问题以及为什么我需要使用 capistrano 部署该解决方法
标签: ruby-on-rails rake environment-variables ruby-on-rails-plugins autoload