require 'couch/core_ext/string/inflections' require 'rubygems' require 'thor/group' module Couch module Generators class Error < Thor::Error end class Base < Thor::Group include Thor::Actions add_runtime_options! # Automatically sets the source root based on the class name. # def self.source_root @_couch_source_root ||= begin if generator_name File.expand_path(File.join("../generators", generator_name, 'templates'), File.dirname(__FILE__)) end end end # Tries to get the description from a USAGE file one folder above the source # root otherwise uses a default description. # def self.desc(description=nil) return super if description usage = File.expand_path(File.join(source_root, "..", "USAGE")) @desc ||= if File.exist?(usage) File.read(usage) else "Description:\n Create files for #{generator_name} generator." end end def self.info desc.split(/\n+/)[1].strip end protected # Use Couch default banner. # def self.banner "couch generate|destroy #{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]" end # Removes the namespaces and get the generator name. For example, # Couch::Generators::MetalGenerator will return "metal" as generator name. # def self.generator_name @generator_name ||= begin if generator = name.to_s.split('::').last generator.sub!(/Generator$/, '') generator.underscore end end end end end end