diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-03 13:01:18 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-03 17:14:49 +0100 |
commit | e88ea3255ff90baa28d30908e1fcb5fa7f7133a8 (patch) | |
tree | 5ffcba7d4eb7add6ff5ddb2b5c3446838a4fd8a5 /railties/lib | |
parent | 6716e4bc0c201d9375fa07b44c1a96b6948fc6ab (diff) | |
download | rails-e88ea3255ff90baa28d30908e1fcb5fa7f7133a8.tar.gz rails-e88ea3255ff90baa28d30908e1fcb5fa7f7133a8.tar.bz2 rails-e88ea3255ff90baa28d30908e1fcb5fa7f7133a8.zip |
Assert for valid application names. [#3556 status:resolved]
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 0073c6ba26..fc6a3cdee8 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -53,8 +53,9 @@ module Rails::Generators def create_root self.destination_root = File.expand_path(app_path, destination_root) - empty_directory '.' + valid_app_const? + empty_directory '.' set_default_accessors! FileUtils.cd(destination_root) end @@ -193,7 +194,14 @@ module Rails::Generators end def app_const - @app_const ||= "#{app_name.classify}::Application" + @app_const ||= "#{app_name.gsub(/\W/, '_').squeeze('_').classify}::Application" + end + + def valid_app_const? + case app_const + when /^\d/ + raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers." + end end def app_secret |