From 22a3416298523d5e8ecb432a263e4bee9441e6c5 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Sun, 10 Apr 2011 12:38:59 +0800 Subject: Add --old-style-hash option to force creating old style hash on Ruby 1.9 That means if you don't like the new syntax, you can pass --old-style-hash to force Rails to generate code with hash rockets. --- railties/lib/rails/generators/app_base.rb | 5 ++++- railties/lib/rails/generators/named_base.rb | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'railties/lib') diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 47dc6ce103..93db5106ce 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -53,6 +53,9 @@ module Rails class_option :help, :type => :boolean, :aliases => "-h", :group => :rails, :desc => "Show this help message and quit" + + class_option :old_style_hash, :type => :boolean, :default => false, + :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9" end def initialize(*args) @@ -177,7 +180,7 @@ module Rails # 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' + if options[:old_style_hash] || RUBY_VERSION < '1.9' ":#{key} => #{value}" else "#{key}: #{value}" diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index 3d19b372ff..36bc9e055c 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -8,6 +8,9 @@ module Rails class_option :skip_namespace, :type => :boolean, :default => false, :desc => "Skip namespace (affects only isolated applications)" + class_option :old_style_hash, :type => :boolean, :default => false, + :desc => "Force using old style hash (:foo => 'bar') on Ruby >= 1.9" + def initialize(args, *options) #:nodoc: # Unfreeze name in case it's given as a frozen string args[0] = args[0].dup if args[0].is_a?(String) && args[0].frozen? @@ -185,7 +188,7 @@ module Rails # 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' + if options[:old_style_hash] || RUBY_VERSION < '1.9' ":#{key} => #{value}" else "#{key}: #{value}" -- cgit v1.2.3