class Adhearsion::Generators::Generator
Public Class Methods
Returns the base root for a common set of generators. This is used to dynamically guess the default source root.
# File lib/adhearsion/generators/generator.rb, line 63 def self.base_root File.dirname __FILE__ end
Returns the default source root for a given generator. This is used internally by adhearsion to set its generators source root. If you want to customize your source root, you should use source_root.
# File lib/adhearsion/generators/generator.rb, line 55 def self.default_source_root return unless generator_name path = File.expand_path File.join(generator_name, 'templates'), base_root path if File.exists?(path) end
Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description.
# File lib/adhearsion/generators/generator.rb, line 29 def self.desc(description = nil) return super if description usage = source_root && File.expand_path("../USAGE", source_root) @desc ||= if usage && File.exist?(usage) ERB.new(File.read(usage)).result(binding) else "#{generator_name} [#{arguments.drop(2).map(&:name).join(', ')}]: #{short_desc}." end end
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.
# File lib/adhearsion/generators/generator.rb, line 47 def self.namespace(name = nil) return super if name @namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':') end
# File lib/adhearsion/generators/generator.rb, line 40 def self.short_desc nil end
Returns the source root for this generator using default_source_root
as default.
# File lib/adhearsion/generators/generator.rb, line 22 def self.source_root(path = nil) @_source_root = path if path @_source_root ||= default_source_root end
Protected Class Methods
Removes the namespaces and get the generator name. For example, Adhearsion::Generators::ModelGenerator will return “model” as generator name.
# File lib/adhearsion/generators/generator.rb, line 72 def self.generator_name @generator_name ||= begin if generator = name.to_s.split('::').last generator.sub!(/Generator$/, '') generator.underscore end end end