Class: Adhearsion::Generators::Generator

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

Class Method Summary collapse

Class Method Details

.base_rootObject

Returns the base root for a common set of generators. This is used to dynamically guess the default source root.



63
64
65
# File 'lib/adhearsion/generators/generator.rb', line 63

def self.base_root
  File.dirname __FILE__
end

.default_source_rootObject

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.



55
56
57
58
59
# 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

.desc(description = nil) ⇒ Object

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



29
30
31
32
33
34
35
36
37
38
# 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

.namespace(name = nil) ⇒ Object

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.



47
48
49
50
# File 'lib/adhearsion/generators/generator.rb', line 47

def self.namespace(name = nil)
  return super if name
  @namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':')
end

.short_descObject



40
41
42
# File 'lib/adhearsion/generators/generator.rb', line 40

def self.short_desc
  nil
end

.source_root(path = nil) ⇒ Object

Returns the source root for this generator using default_source_root as default.



22
23
24
25
# 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