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/generators/base.rb | |
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/generators/base.rb')
-rw-r--r-- | railties/lib/generators/base.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index c1acd4c94f..1be0dd6ec2 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -110,7 +110,7 @@ module Rails names.each do |name| defaults = if options[:type] == :boolean { } - elsif [true, false].include?(options.fetch(:default, Rails::Generators.options[name])) + elsif [true, false].include?(options.fetch(:default, default_value_for_option(name))) { :banner => "" } else { :desc => "#{name.to_s.humanize} to be invoked", :banner => "NAME" } @@ -143,8 +143,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] = Rails::Generators.aliases[name] unless options.key?(:aliases) - options[:default] = Rails::Generators.options[name] unless options.key?(:default) + options[:aliases] = default_aliases_for_option(name) unless options.key?(:aliases) + options[:default] = default_value_for_option(name) unless options.key?(:default) super(name, options) end @@ -205,6 +205,36 @@ module Rails end end + # 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 + + if options[generator_name.to_sym].key?(option) + options[generator_name.to_sym][option] + elsif options[base_name.to_sym].key?(option) + options[base_name.to_sym][option] + else + options[:rails][option] + 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 + + if aliases[generator_name.to_sym].key?(option) + aliases[generator_name.to_sym][option] + elsif aliases[base_name.to_sym].key?(option) + aliases[base_name.to_sym][option] + else + aliases[:rails][option] + end + end + # Keep hooks configuration that are used on prepare_for_invocation. # def self.hooks #:nodoc: |