aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorlest <just.lest@gmail.com>2011-11-19 19:03:44 +0200
committerlest <just.lest@gmail.com>2011-11-19 19:09:09 +0200
commit39d2251d8a3e50bf004b6361e0079679466b2280 (patch)
tree730fc5f830836cb8b55d31d6b90d7c789854cf08 /railties/lib
parentbc04455f1032166e66f5aef06ff2976173ac7da6 (diff)
downloadrails-39d2251d8a3e50bf004b6361e0079679466b2280.tar.gz
rails-39d2251d8a3e50bf004b6361e0079679466b2280.tar.bz2
rails-39d2251d8a3e50bf004b6361e0079679466b2280.zip
fix rails plugin new CamelCasedName bug
refs #3684
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
index f5c8ccf940..ff523fc26f 100644
--- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
+++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb
@@ -246,8 +246,20 @@ task :default => :test
"rails plugin new #{self.arguments.map(&:usage).join(' ')} [options]"
end
+ def original_name
+ @original_name ||= File.basename(destination_root)
+ end
+
def name
- @name ||= File.basename(destination_root)
+ unless @name
+ # same as ActiveSupport::Inflector#underscore except not replacing '-'
+ @name = original_name.dup
+ @name.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
+ @name.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
+ @name.downcase!
+ end
+
+ @name
end
def camelized
@@ -256,11 +268,11 @@ task :default => :test
def valid_const?
if camelized =~ /^\d/
- raise Error, "Invalid plugin name #{name}. Please give a name which does not start with numbers."
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which does not start with numbers."
elsif RESERVED_NAMES.include?(name)
- raise Error, "Invalid plugin name #{name}. Please give a name which does not match one of the reserved rails words."
+ raise Error, "Invalid plugin name #{original_name}. Please give a name which does not match one of the reserved rails words."
elsif Object.const_defined?(camelized)
- raise Error, "Invalid plugin name #{name}, constant #{camelized} is already in use. Please choose another plugin name."
+ raise Error, "Invalid plugin name #{original_name}, constant #{camelized} is already in use. Please choose another plugin name."
end
end