diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-24 15:33:38 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-25 10:39:43 +0200 |
commit | a748bb796145981c65cb6d342b4b3b02ef4c0ba0 (patch) | |
tree | b4bdc854065da573046e831ade6ad925a5a52903 /railties/lib/generators/base.rb | |
parent | 0ed602b3ef3351441b9edca59a7a1da6633a4e32 (diff) | |
download | rails-a748bb796145981c65cb6d342b4b3b02ef4c0ba0.tar.gz rails-a748bb796145981c65cb6d342b4b3b02ef4c0ba0.tar.bz2 rails-a748bb796145981c65cb6d342b4b3b02ef4c0ba0.zip |
Get base_name from class_name.
Diffstat (limited to 'railties/lib/generators/base.rb')
-rw-r--r-- | railties/lib/generators/base.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/railties/lib/generators/base.rb b/railties/lib/generators/base.rb index 4f394d2e38..e40c018a59 100644 --- a/railties/lib/generators/base.rb +++ b/railties/lib/generators/base.rb @@ -15,13 +15,15 @@ module Rails @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), base_name, generator_name, 'templates')) end - # Convenience method to get the namespace from the class name. + # Convenience method to get the namespace from the class name. It's the + # same as Thor default except that the Generator at the end of the class + # is removed. # - def self.namespace(name=nil) + def self.namespace(name=nil) #:nodoc: if name super else - @namespace ||= "#{base_name}:#{generator_name}" + @namespace ||= "#{base_name}:generators:#{generator_name}" end end @@ -33,18 +35,15 @@ module Rails "#{$0} #{generator_name} #{self.arguments.map(&:usage).join(' ')} [options]" end - # Sets the base_name. Overwriten by test unit generators. + # Sets the base_name taking into account the current class namespace. # - def self.base_name - 'rails' + def self.base_name #:nodoc: + @base_name ||= self.name.split('::').first.underscore end # Removes the namespaces and get the generator name. For example, # Rails::Generators::MetalGenerator will return "metal" as generator name. # - # The name is used to set the namespace (in this case "rails:metal") - # and to set the source root ("rails/metal/templates"). - # def self.generator_name @generator_name ||= begin klass_name = self.name.split('::').last @@ -61,7 +60,7 @@ module Rails default = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) class_option :ruby, :type => :string, :aliases => "-r", :default => default, - :desc => "Path to the Ruby binary of your choice" + :desc => "Path to the Ruby binary of your choice", :banner => "PATH" no_tasks do define_method :shebang do @@ -78,7 +77,7 @@ module Rails define_method :invoke_test_framework do return unless options[:test_framework] - name = "#{options[:test_framework]}:#{self.class.generator_name}" + name = "#{options[:test_framework]}:generators:#{self.class.generator_name}" begin invoke name |