diff options
author | Prem Sichanugrist <s@sikachu.com> | 2011-04-10 12:30:58 +0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2011-04-10 16:47:51 +0800 |
commit | 74960c3976a69b3c7d9aa6bf28edb42ea82df0ce (patch) | |
tree | c589bace5fc2cb711d145ee82b9120197cc2c00f /railties/lib/rails/generators | |
parent | 63cd92f9f346acefca1ad014873c971837843cdb (diff) | |
download | rails-74960c3976a69b3c7d9aa6bf28edb42ea82df0ce.tar.gz rails-74960c3976a69b3c7d9aa6bf28edb42ea82df0ce.tar.bz2 rails-74960c3976a69b3c7d9aa6bf28edb42ea82df0ce.zip |
Rails will now generate Ruby 1.9 style hash when running app generator on Ruby 1.9.x
The new hash syntax of Ruby 1.9 looks more superior, so we decide to switch to it in the places that appropriate.
Diffstat (limited to 'railties/lib/rails/generators')
3 files changed, 12 insertions, 3 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index a2eaf7a6fb..47dc6ce103 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -174,6 +174,15 @@ module Rails create_file("#{destination}/.gitkeep") unless options[:skip_git] end + # Returns Ruby 1.9 style key-value pair if current code is running on + # Ruby 1.9.x. Returns the old-style (with hash rocket) otherwise. + def key_value(key, value) + if RUBY_VERSION < '1.9' + ":#{key} => #{value}" + else + "#{key}: #{value}" + end + end end end end diff --git a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt index 62aa06dc3e..ddfe4ba1e1 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -<%= app_const %>.config.session_store :cookie_store, :key => '_<%= app_name %>_session' +<%= app_const %>.config.session_store :cookie_store, <%= key_value :key, "'_#{app_name}_session'" %> # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/railties/lib/rails/generators/rails/app/templates/db/seeds.rb b/railties/lib/rails/generators/rails/app/templates/db/seeds.rb index 664d8c74c8..9a2efa68a7 100644 --- a/railties/lib/rails/generators/rails/app/templates/db/seeds.rb +++ b/railties/lib/rails/generators/rails/app/templates/db/seeds.rb @@ -3,5 +3,5 @@ # # Examples: # -# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) -# Mayor.create(:name => 'Daley', :city => cities.first) +# cities = City.create([{ <%= key_value :name, "'Chicago'" %> }, { <%= key_value :name, "'Copenhagen'" %> }]) +# Mayor.create(<%= key_value :name, "'Daley'" %>, <%= key_value :city, "cities.first" %>) |