diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-28 08:48:21 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-28 08:48:21 +0200 |
commit | 419ca7a747dd2f33078f12c32b98d3b7ea0bffdb (patch) | |
tree | 4031f9a285e135934644db5f3f268f212376b71c /railties | |
parent | 67c2f53938654381d5d19bbdd046b82c6268aaff (diff) | |
download | rails-419ca7a747dd2f33078f12c32b98d3b7ea0bffdb.tar.gz rails-419ca7a747dd2f33078f12c32b98d3b7ea0bffdb.tar.bz2 rails-419ca7a747dd2f33078f12c32b98d3b7ea0bffdb.zip |
Ensure that developers options are overwritten by user options.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/generators/base.rb | 38 | ||||
-rw-r--r-- | railties/test/generators_test.rb | 14 |
2 files changed, 35 insertions, 17 deletions
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index a6a2998af5..cbe9c0a49d 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -111,7 +111,7 @@ module Rails names.each do |name| defaults = if options[:type] == :boolean { } - elsif [true, false].include?(options.fetch(:default, default_value_for_option(name))) + elsif [true, false].include?(default_value_for_option(name, options)) { :banner => "" } else { :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" } @@ -144,8 +144,8 @@ module Rails # def self.class_option(name, options={}) #:nodoc: options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc) - options[:aliases] = default_aliases_for_option(name) unless options.key?(:aliases) - options[:default] = default_value_for_option(name) unless options.key?(:default) + options[:aliases] = default_aliases_for_option(name, options) + options[:default] = default_value_for_option(name, options) super(name, options) end @@ -226,32 +226,36 @@ module Rails # Return the default value for the option name given doing a lookup in # Rails::Generators.options. # - def self.default_value_for_option(option) - options = Rails::Generators.options + def self.default_value_for_option(name, options) + config = Rails::Generators.options generator, base = generator_name.to_sym, base_name.to_sym - if options[generator] && options[generator].key?(option) - options[generator][option] - elsif options[base] && options[base].key?(option) - options[base][option] + if config[generator] && config[generator].key?(name) + config[generator][name] + elsif config[base] && config[base].key?(name) + config[base][name] + elsif config[:rails].key?(name) + config[:rails][name] else - options[:rails][option] + options[:default] end end # Return default aliases for the option name given doing a lookup in # Rails::Generators.aliases. # - def self.default_aliases_for_option(option) - aliases = Rails::Generators.aliases + def self.default_aliases_for_option(name, options) + config = Rails::Generators.aliases generator, base = generator_name.to_sym, base_name.to_sym - if aliases[generator] && aliases[generator].key?(option) - aliases[generator][option] - elsif aliases[base] && aliases[base].key?(option) - aliases[base][option] + if config[generator] && config[generator].key?(name) + config[generator][name] + elsif config[base] && config[base].key?(name) + config[base][name] + elsif config[:rails].key?(name) + config[:rails][name] else - aliases[:rails][option] + options[:aliases] end end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index ea3f7d5487..103f9b7def 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -134,4 +134,18 @@ class GeneratorsTest < GeneratorsTestCase TestUnit::Generators::ModelGenerator.expects(:start).with(["Account"], {}) Rails::Generators.invoke "super_shoulda:model", ["Account"] end + + def test_developer_options_are_overwriten_by_user_options + Rails::Generators.options[:new_generator] = { :generate => false } + + klass = Class.new(Rails::Generators::Base) do + def self.name + "NewGenerator" + end + + class_option :generate, :default => true + end + + assert_equal false, klass.class_options[:generate].default + end end |