diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-15 16:20:48 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-15 16:20:48 +0200 |
commit | 7022b58842ec3490d85efc5b947d86a0fd72d0cb (patch) | |
tree | ad1134b23961e64f6f754863f82dfeb2e3e0c8b2 /railties/lib/rails | |
parent | 0702e04e0d671227259f71f614adfe3f35f88b48 (diff) | |
download | rails-7022b58842ec3490d85efc5b947d86a0fd72d0cb.tar.gz rails-7022b58842ec3490d85efc5b947d86a0fd72d0cb.tar.bz2 rails-7022b58842ec3490d85efc5b947d86a0fd72d0cb.zip |
Allow namespaced configuration on generators.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/configuration.rb | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 1a8f261e6f..edbec6ad70 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -252,23 +252,22 @@ module Rails # Holds generators configuration: # - # config.generators.orm = :datamapper - # config.generators.test_framework = :rspec - # config.generators.template_engine = :haml - # - # A block can also be given for less verbose configuration: - # # config.generators do |g| - # g.orm = :datamapper - # g.test_framework = :datamapper - # g.template_engine = :haml - # end + # g.orm :datamapper do |dm| + # dm.migration = true + # dm.timestamps = false + # end # - # You can also configure/override aliases: + # g.template_engine = :haml + # g.test_framework = :datamapper # - # config.generators.aliases = :test_framework => "-w" + # g.plugin do |p| + # p.aliases :generator => "-g" + # p.generator = true + # end + # end # - # Finally, to disable color in console, do: + # If you want to disable color in console, do: # # config.generators.colorize_logging = false # @@ -282,18 +281,30 @@ module Rails end class Generators #:nodoc: - attr_accessor :aliases, :options, :colorize_logging + attr_reader :aliases, :options + attr_accessor :colorize_logging def initialize - @aliases, @options, @colorize_logging = {}, {}, true + @namespace, @colorize_logging = :rails, true + @aliases = Hash.new { |h,k| h[k] = {} } + @options = Hash.new { |h,k| h[k] = {} } end - def method_missing(method, *args, &block) - method = method.to_s - if method.gsub!(/=$/, '') - @options[method.to_sym] = args.first - else - super(method.to_sym, *args, &block) + 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 if args.first + + if block_given? + previous_namespace = @namespace + @namespace = (args.first || sanitized_method).to_sym + yield self + @namespace = previous_namespace end end end |