Class: Couch::Generators::Base

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/couch/generators/base.rb

Direct Known Subclasses

ApplicationGenerator, NamedBase

Class Method Summary collapse

Class Method Details

.desc(description = nil) ⇒ Object

Tries to get the description from a USAGE file one folder above the source root otherwise uses a default description.



30
31
32
33
34
35
36
37
38
39
# File 'lib/couch/generators/base.rb', line 30

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

.infoObject



41
42
43
# File 'lib/couch/generators/base.rb', line 41

def self.info
  desc.split(/\n+/)[1].strip
end

.source_rootObject

Automatically sets the source root based on the class name.



19
20
21
22
23
24
25
# File 'lib/couch/generators/base.rb', line 19

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