Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added config.app_generators to allow configuring application's genera…

…tors 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
  • Loading branch information...
commit f851352318c7468db310e5fbea0d86dc8b731c6d 1 parent 57aa79e
Piotr Sarnacki drogus authored
2  activerecord/lib/active_record/railtie.rb
View
@@ -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",
1  railties/lib/rails/application/configuration.rb
View
@@ -24,6 +24,7 @@ def initialize(*)
@time_zone = "UTC"
@middleware = app_middleware
@asset_path = '/'
+ @generators = app_generators
end
def asset_path=(value)
19 railties/lib/rails/railtie/configuration.rb
View
@@ -17,6 +17,19 @@ def app_middleware
@@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 @@ def app_middleware
# 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
2  railties/lib/rails/test_unit/railtie.rb
View
@@ -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
39 railties/test/railties/engine_test.rb
View
@@ -703,5 +703,44 @@ class Engine < ::Rails::Engine
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
Please sign in to comment.
Something went wrong with that request. Please try again.