i tried to disable autoloading of plugins in my environment.rb for the rake task "gems:install", since it may lead to unresolved dependencies and errors (read http://blog.joopp.com/2009/01/26/plugin-gem-dependencies-in-your-environmentrb/ for further information).
While implementing this "hack", i quickly noticed that the variable $rails_gem_installer, which should be set to true if gems:install is run, is not set. (==nil)
Now i'm looking for a way to get information about the called rake task, or is there any other working solution?
Im running Rails 2.3.10 / Ruby 1.8.7
Here's the code from my environment.rb for better understanding:
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]
Instead of going down the road of getting rake gems:install
to work properly, which was something that never seemed to work properly in every situation, it might be better to port your dependencies to bundler instead. Although this is how Rails 3 is configured by default, it can be used on any ruby project and does a much better job.
A Gemfile
also serves as a human-readable manifest of dependencies, something that's not always easily extracted from a Rails configuration file.
There's an example on using bundler with Rails 2.3 on their site: http://gembundler.com/rails23.html