diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-15 23:38:41 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-15 23:38:41 +0200 |
commit | 9c4ba74b7cd74b0312425ecc8c5b57aa6cf8c0d5 (patch) | |
tree | a9312f22db2acd9abd8ea67a5adc9bc18b89235f | |
parent | bcf754d8c471187da386e147707598e5c8e52090 (diff) | |
download | rails-9c4ba74b7cd74b0312425ecc8c5b57aa6cf8c0d5.tar.gz rails-9c4ba74b7cd74b0312425ecc8c5b57aa6cf8c0d5.tar.bz2 rails-9c4ba74b7cd74b0312425ecc8c5b57aa6cf8c0d5.zip |
Change generators configuration to have a hash style.
-rw-r--r-- | railties/lib/generators/rails/app/templates/config/environment.rb | 23 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 45 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 47 |
3 files changed, 39 insertions, 76 deletions
diff --git a/railties/lib/generators/rails/app/templates/config/environment.rb b/railties/lib/generators/rails/app/templates/config/environment.rb index 59c1f0bfb2..94c90475c6 100644 --- a/railties/lib/generators/rails/app/templates/config/environment.rb +++ b/railties/lib/generators/rails/app/templates/config/environment.rb @@ -43,24 +43,11 @@ Rails::Initializer.run do |config| # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')] # config.i18n.default_locale = :de - # Configure generators default options. + # Configure generators values. Many other options are available, be sure to + # check the documentation. config.generators do |g| - g.rails do |r| - r.helper = true - r.stylesheets = true - end - - g.orm :active_record do |ar| - ar.migration = true - ar.timestamps = true - end - - g.template_engine :erb do |erb| - erb.layout = true - end - - g.test_framework :test_unit do |tu| - tu.fixtures = true - end + g.orm :active_record + g.template_engine :erb + g.test_framework :test_unit, :fixture => true end end diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 4c68ace779..fe3cb67d3a 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -253,18 +253,9 @@ module Rails # Holds generators configuration: # # config.generators do |g| - # g.orm :datamapper do |dm| - # dm.migration = true - # dm.timestamps = false - # end - # - # g.template_engine = :haml - # g.test_framework = :datamapper - # - # g.plugin do |p| - # p.aliases :generator => "-g" - # p.generator = true - # end + # g.orm :datamapper, :migration => true + # g.template_engine :haml + # g.test_framework :rspec # end # # If you want to disable color in console, do: @@ -281,30 +272,26 @@ module Rails end class Generators #:nodoc: - attr_reader :aliases, :options - attr_accessor :colorize_logging + attr_accessor :aliases, :options, :colorize_logging def initialize - @namespace, @colorize_logging = :rails, true @aliases = Hash.new { |h,k| h[k] = {} } @options = Hash.new { |h,k| h[k] = {} } + @colorize_logging = true end - def aliases(another=nil) - @aliases[@namespace].merge!(another) if another - @aliases - end - alias :aliases= :aliases - def method_missing(method, *args) - sanitized_method = method.to_s.sub(/=$/, '').to_sym - @options[@namespace][sanitized_method] = args.first unless args.empty? - - if block_given? - previous_namespace = @namespace - @namespace = (args.first || sanitized_method).to_sym - yield self - @namespace = previous_namespace + method = method.to_s.sub(/=$/, '').to_sym + namespace = args.first.is_a?(Symbol) ? args.shift : nil + configuration = args.first.is_a?(Hash) ? args.shift : nil + + @options[:rails][method] = namespace if namespace + namespace ||= method + + if configuration + aliases = configuration.delete(:aliases) + @aliases[namespace].merge!(aliases) if aliases + @options[namespace].merge!(configuration) end end end diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 96553524da..1fecd62995 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -312,22 +312,13 @@ class InitializerGeneratorsTests < Test::Unit::TestCase end def test_generators_set_rails_aliases - @configuration.generators.aliases = { :test_framework => "-w" } + @configuration.generators.aliases = { :rails => { :test_framework => "-w" } } expected = { :rails => { :test_framework => "-w" } } assert_equal expected, @configuration.generators.aliases end - def test_generators_with_block_for_rails_configuration - @configuration.generators do |g| - g.orm = :datamapper - g.test_framework = :rspec - end - expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } } - assert_equal expected, @configuration.generators.options - end - def test_generators_aliases_and_options_on_initialization - @configuration.generators.aliases :test_framework => "-w" + @configuration.generators.rails :aliases => { :test_framework => "-w" } @configuration.generators.orm :datamapper @configuration.generators.test_framework :rspec @@ -343,39 +334,37 @@ class InitializerGeneratorsTests < Test::Unit::TestCase assert_equal Thor::Base.shell, Thor::Shell::Basic end - def test_generators_with_namespaced_blocks_for_options_and_aliases - namespaced_configuration! + def test_generators_with_hashes_for_options_and_aliases + @configuration.generators do |g| + g.orm :datamapper, :migration => false + g.plugin :aliases => { :generator => "-g" }, + :generator => true + end + expected = { :rails => { :orm => :datamapper }, :plugin => { :generator => true }, - :datamapper => { :migrations => false } + :datamapper => { :migration => false } } + assert_equal expected, @configuration.generators.options assert_equal({ :plugin => { :generator => "-g" } }, @configuration.generators.aliases) end - def test_generators_with_namespaced_configuration_are_deep_merged - namespaced_configuration! + def test_generators_with_hashes_are_deep_merged + @configuration.generators do |g| + g.orm :datamapper, :migration => false + g.plugin :aliases => { :generator => "-g" }, + :generator => true + end @initializer.run(:initialize_generators) + assert Rails::Generators.aliases.size >= 1 assert Rails::Generators.options.size >= 1 end protected - def namespaced_configuration! - @configuration.generators do |g| - g.orm :datamapper do |dm| - dm.migrations = false - end - - g.plugin do |p| - p.aliases = { :generator => "-g" } - p.generator = true - end - end - end - def teardown Rails::Generators.clear_aliases! Rails::Generators.clear_options! |