From 2699e9c2ddff13c5e19e1c95e838fa6d9a965c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 8 Jul 2009 10:57:56 +0200 Subject: Added config.generators with tests. --- railties/lib/rails/configuration.rb | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/configuration.rb') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 1a2f217d20..4a5fe4da7d 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -249,5 +249,52 @@ module Rails def reload_plugins? @reload_plugins end + + # 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 + # + # You can also configure/override aliases: + # + # config.generators.aliases :test_framework => "-w" + # + def generators + @generators ||= Generators.new + if block_given? + yield @generators + else + @generators + end + end + + class Generators #:nodoc: + def initialize + @aliases, @options = {}, {} + end + + def aliases(values=nil) + @aliases = values if values + @aliases + end + + def options(values=nil) + @options = values if values + @options + end + + def method_missing(method, *args, &block) + @options[method.to_sym] = args.first + end + end end -end \ No newline at end of file +end -- cgit v1.2.3 From c9ea21717eefb9e9b49891c519cc4d121ef7bb74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 8 Jul 2009 12:19:17 +0200 Subject: Generators are configured on initialization if RAILS_ENV=generators. --- railties/lib/rails/configuration.rb | 39 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'railties/lib/rails/configuration.rb') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 4a5fe4da7d..1a8f261e6f 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -252,21 +252,25 @@ module Rails # Holds generators configuration: # - # config.generators.orm :datamapper - # config.generators.test_framework :rspec - # config.generators.template_engine :haml + # 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 + # g.orm = :datamapper + # g.test_framework = :datamapper + # g.template_engine = :haml # end # # You can also configure/override aliases: # - # config.generators.aliases :test_framework => "-w" + # config.generators.aliases = :test_framework => "-w" + # + # Finally, to disable color in console, do: + # + # config.generators.colorize_logging = false # def generators @generators ||= Generators.new @@ -278,22 +282,19 @@ module Rails end class Generators #:nodoc: - def initialize - @aliases, @options = {}, {} - end + attr_accessor :aliases, :options, :colorize_logging - def aliases(values=nil) - @aliases = values if values - @aliases - end - - def options(values=nil) - @options = values if values - @options + def initialize + @aliases, @options, @colorize_logging = {}, {}, true end def method_missing(method, *args, &block) - @options[method.to_sym] = args.first + method = method.to_s + if method.gsub!(/=$/, '') + @options[method.to_sym] = args.first + else + super(method.to_sym, *args, &block) + end end end end -- cgit v1.2.3 From 7022b58842ec3490d85efc5b947d86a0fd72d0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 16:20:48 +0200 Subject: Allow namespaced configuration on generators. --- railties/lib/rails/configuration.rb | 53 ++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'railties/lib/rails/configuration.rb') 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 -- cgit v1.2.3 From baa4781ac7174e527c2471b4c86ea51c0f65cf6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 16:53:54 +0200 Subject: Allow nil and false to be given as configuration values and avoid creating unecessary hashes. --- railties/lib/rails/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/configuration.rb') diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index edbec6ad70..4c68ace779 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -298,7 +298,7 @@ module Rails def method_missing(method, *args) sanitized_method = method.to_s.sub(/=$/, '').to_sym - @options[@namespace][sanitized_method] = args.first if args.first + @options[@namespace][sanitized_method] = args.first unless args.empty? if block_given? previous_namespace = @namespace -- cgit v1.2.3 From 9c4ba74b7cd74b0312425ecc8c5b57aa6cf8c0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 23:38:41 +0200 Subject: Change generators configuration to have a hash style. --- railties/lib/rails/configuration.rb | 45 +++++++++++++------------------------ 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'railties/lib/rails/configuration.rb') 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 -- cgit v1.2.3