diff options
author | José Valim <jose.valim@gmail.com> | 2009-07-15 16:53:54 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-07-15 16:53:54 +0200 |
commit | baa4781ac7174e527c2471b4c86ea51c0f65cf6b (patch) | |
tree | ac8fac2379845ce30d9e502ff4511be0488a0dd1 /railties/lib | |
parent | 7022b58842ec3490d85efc5b947d86a0fd72d0cb (diff) | |
download | rails-baa4781ac7174e527c2471b4c86ea51c0f65cf6b.tar.gz rails-baa4781ac7174e527c2471b4c86ea51c0f65cf6b.tar.bz2 rails-baa4781ac7174e527c2471b4c86ea51c0f65cf6b.zip |
Allow nil and false to be given as configuration values and avoid creating unecessary hashes.
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/generators.rb | 10 | ||||
-rw-r--r-- | railties/lib/generators/base.rb | 18 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 2 |
3 files changed, 15 insertions, 15 deletions
diff --git a/railties/lib/generators.rb b/railties/lib/generators.rb index 6935cb8319..3286e8b2dd 100644 --- a/railties/lib/generators.rb +++ b/railties/lib/generators.rb @@ -17,8 +17,7 @@ require 'generators/named_base' module Rails module Generators - DEFAULT_ALIASES = Hash.new{ |h,k| h[k] = {} } - DEFAULT_ALIASES.merge!( + DEFAULT_ALIASES = { :rails => { :actions => '-a', :orm => '-o', @@ -37,10 +36,9 @@ module Rails :generator => '-g', :tasks => '-r' } - ) + } - DEFAULT_OPTIONS = Hash.new{ |h,k| h[k] = {} } - DEFAULT_OPTIONS.merge!( + DEFAULT_OPTIONS = { :active_record => { :migration => true, :timestamps => true @@ -74,7 +72,7 @@ module Rails :generator => false, :tasks => false } - ) + } def self.aliases @@aliases ||= DEFAULT_ALIASES.dup diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index 1be0dd6ec2..0ef6d061ff 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -210,11 +210,12 @@ module Rails # def self.default_value_for_option(option) options = Rails::Generators.options + generator, base = generator_name.to_sym, base_name.to_sym - 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] + if options[generator] && options[generator].key?(option) + options[generator][option] + elsif options[base] && options[base].key?(option) + options[base][option] else options[:rails][option] end @@ -225,11 +226,12 @@ module Rails # def self.default_aliases_for_option(option) aliases = Rails::Generators.aliases + generator, base = generator_name.to_sym, base_name.to_sym - 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] + if aliases[generator] && aliases[generator].key?(option) + aliases[generator][option] + elsif aliases[base] && aliases[base].key?(option) + aliases[base][option] else aliases[:rails][option] end 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 |