From b1999be5a7efd67e2602c37ed898aa8433661863 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 15 Feb 2005 01:45:35 +0000 Subject: A hopefully more successful attempt at the Routing branch merge git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@617 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/rails_generator/base.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'railties/lib/rails_generator/base.rb') diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb index 065ce63966..92a54e2453 100644 --- a/railties/lib/rails_generator/base.rb +++ b/railties/lib/rails_generator/base.rb @@ -1,5 +1,5 @@ -require File.dirname(__FILE__) + '/../support/class_attribute_accessors' -require File.dirname(__FILE__) + '/../support/inflector' +require File.dirname(__FILE__) + '/support/class_attribute_accessors' +require File.dirname(__FILE__) + '/support/inflector' require File.dirname(__FILE__) + '/options' require File.dirname(__FILE__) + '/manifest' require File.dirname(__FILE__) + '/spec' @@ -69,8 +69,8 @@ module Rails @source_root = options[:source] || File.join(spec.path, 'templates') if options[:destination] @destination_root = options[:destination] - elsif Object.const_defined?(:RAILS_ROOT) - @destination_root = Object.const_get(:RAILS_ROOT) + elsif defined? ::RAILS_ROOT + @destination_root = ::RAILS_ROOT end # Silence the logger if requested. @@ -173,11 +173,20 @@ module Rails def assign_names!(name) @name = name base_name, @class_path, @class_nesting = extract_modules(@name) - @class_name, @singular_name, @plural_name = inflect_names(base_name) + @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) + if @class_nesting.empty? + @class_name = @class_name_without_nesting + else + @class_name = "#{@class_nesting}::#{@class_name_without_nesting}" + end end + # Extract modules from filesystem-style or ruby-style path: + # good/fun/stuff + # Good::Fun::Stuff + # produce the same results. def extract_modules(name) - modules = name.split('/') + modules = name.include?('/') ? name.split('/') : name.split('::') name = modules.pop path = modules.map { |m| m.underscore } nesting = modules.map { |m| m.camelize }.join('::') -- cgit v1.2.3