diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-23 14:42:59 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-23 16:53:47 +0200 |
commit | 1845675822fef4ead89b8919da56c4fadb145e56 (patch) | |
tree | b536919097f2d52fcdc6502d39018bc38f0af58e /railties/lib/generator/base.rb | |
parent | f03890e151d7a8b9cc413ea9955efc95ff4fbfe6 (diff) | |
download | rails-1845675822fef4ead89b8919da56c4fadb145e56.tar.gz rails-1845675822fef4ead89b8919da56c4fadb145e56.tar.bz2 rails-1845675822fef4ead89b8919da56c4fadb145e56.zip |
Added metal generator.
Diffstat (limited to 'railties/lib/generator/base.rb')
-rw-r--r-- | railties/lib/generator/base.rb | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/railties/lib/generator/base.rb b/railties/lib/generator/base.rb index 8751cb08fb..08f488932b 100644 --- a/railties/lib/generator/base.rb +++ b/railties/lib/generator/base.rb @@ -23,9 +23,16 @@ module Rails # Automatically sets the source root based on the class name. # def self.source_root - @source_root ||= begin - klass_name = self.name.gsub(/^Rails::Generators::/, '') - File.expand_path(File.join(File.dirname(__FILE__), 'generators', klass_name.underscore, 'templates')) + @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'generators', generator_name, 'templates')) + end + + # Convenience method to get the namespace from the class name. + # + def self.namespace(name=nil) + if name + super + else + @namespace ||= "rails:generators:#{generator_name}" end end @@ -34,11 +41,26 @@ module Rails # Use Rails default banner. # def self.banner - "#{$0} #{self.arguments.map(&:usage).join(' ')} [options]" + "#{$0} #{generator_name} #{self.arguments.map(&:usage).join(' ')} [options]" + 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:generators:metal") + # and to set the source root ("generators/metal/templates"). + # + def self.generator_name + @generator_name ||= begin + klass_name = self.name + klass_name.gsub!(/^Rails::Generators::/, '') + klass_name.gsub!(/Generator$/, '') + klass_name.underscore + end end - # Small macro to ruby as an option to the generator with proper default - # value plus an instance helper method. + # Small macro to add ruby as an option to the generator with proper + # default value plus an instance helper method called shebang. # def self.add_shebang_option! require 'rbconfig' |