diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-09-29 17:41:30 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-30 09:47:06 +0200 |
commit | f851352318c7468db310e5fbea0d86dc8b731c6d (patch) | |
tree | 4d040546fdc495c1f79b580d42c1e3236e5063d1 | |
parent | 57aa79e6bedeffcff899688546ef0a508948b4a5 (diff) | |
download | rails-f851352318c7468db310e5fbea0d86dc8b731c6d.tar.gz rails-f851352318c7468db310e5fbea0d86dc8b731c6d.tar.bz2 rails-f851352318c7468db310e5fbea0d86dc8b731c6d.zip |
Added config.app_generators to allow configuring application's generators from railties.
With config.generators becomes a way to configure generators
for current instance only. For example:
module Blog
class Engine < Rails::Engine
config.generators do |g|
g.orm :active_record
end
config.app_generators do |g|
g.test_framework :rspec
end
end
end
such definition sets :active_record as orm for engine and :rspec
as test_framework for application. The values set with app_generators
can be overwritten in application using config.generators as you would
normally do:
module MyApp
class Application < Rails::Application
config.generators do |g|
g.test_framework :test_unit
end
end
end
-rw-r--r-- | activerecord/lib/active_record/railtie.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/railtie/configuration.rb | 19 | ||||
-rw-r--r-- | railties/lib/rails/test_unit/railtie.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 39 |
5 files changed, 58 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index 94dda4e413..868fd6c3ff 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -13,7 +13,7 @@ module ActiveRecord class Railtie < Rails::Railtie config.active_record = ActiveSupport::OrderedOptions.new - config.generators.orm :active_record, :migration => true, + config.app_generators.orm :active_record, :migration => true, :timestamps => true config.app_middleware.insert_after "::ActionDispatch::Callbacks", diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a0ecbc0fc8..f902c3ded2 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -24,6 +24,7 @@ module Rails @time_zone = "UTC" @middleware = app_middleware @asset_path = '/' + @generators = app_generators end def asset_path=(value) diff --git a/railties/lib/rails/railtie/configuration.rb b/railties/lib/rails/railtie/configuration.rb index f09e3940cc..e0e4324a4a 100644 --- a/railties/lib/rails/railtie/configuration.rb +++ b/railties/lib/rails/railtie/configuration.rb @@ -17,6 +17,19 @@ module Rails @@app_middleware ||= Rails::Configuration::MiddlewareStackProxy.new end + # This allows you to modify application's generators from Railties. + # + # Values set on app_generators will become defaults for applicaiton, unless + # application overwrites them. + def app_generators + @@app_generators ||= Rails::Configuration::Generators.new + if block_given? + yield @@app_generators + else + @@app_generators + end + end + # Holds generators configuration: # # config.generators do |g| @@ -30,11 +43,11 @@ module Rails # config.generators.colorize_logging = false # def generators - @@generators ||= Rails::Configuration::Generators.new + @generators ||= Rails::Configuration::Generators.new if block_given? - yield @@generators + yield @generators else - @@generators + @generators end end diff --git a/railties/lib/rails/test_unit/railtie.rb b/railties/lib/rails/test_unit/railtie.rb index e3fafc4b9d..2b6170ebfb 100644 --- a/railties/lib/rails/test_unit/railtie.rb +++ b/railties/lib/rails/test_unit/railtie.rb @@ -1,6 +1,6 @@ module Rails class TestUnitRailtie < Rails::Railtie - config.generators do |c| + config.app_generators do |c| c.test_framework :test_unit, :fixture => true, :fixture_replacement => nil diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 2b9d728b0c..c75639d740 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -703,5 +703,44 @@ module RailtiesTest get "/bukkits/bar" assert_equal "bar", last_response.body end + + test "setting generators for engine and overriding app generator's" do + @plugin.write "lib/bukkits.rb", <<-RUBY + module Bukkits + class Engine < ::Rails::Engine + config.generators do |g| + g.orm :datamapper + g.template_engine :haml + g.test_framework :rspec + end + + config.app_generators do |g| + g.orm :mongoid + g.template_engine :liquid + g.test_framework :shoulda + end + end + end + RUBY + + add_to_config <<-RUBY + config.generators do |g| + g.test_framework :test_unit + end + RUBY + + boot_rails + require "#{rails_root}/config/environment" + + app_generators = Rails.application.config.generators.options[:rails] + assert_equal :mongoid , app_generators[:orm] + assert_equal :liquid , app_generators[:template_engine] + assert_equal :test_unit, app_generators[:test_framework] + + generators = Bukkits::Engine.config.generators.options[:rails] + assert_equal :datamapper, generators[:orm] + assert_equal :haml , generators[:template_engine] + assert_equal :rspec , generators[:test_framework] + end end end |