Module: Adhearsion::Generators

Defined in:
lib/adhearsion/generators.rb,
lib/adhearsion/generators/generator.rb,
lib/adhearsion/generators/app/app_generator.rb,
lib/adhearsion/generators/plugin/plugin_generator.rb,
lib/adhearsion/generators/controller/controller_generator.rb

Defined Under Namespace

Classes: AppGenerator, ControllerGenerator, Generator, PluginGenerator

Class Method Summary collapse

Class Method Details

.add_generator(name, klass) ⇒ Hash

Globally add a new generator class to ahn generate

Examples:

Adhearsion::Generators.add_generator :myplugin, MyPluginGenerator

Parameters:

  • name (Symbol)

    key name for generator mapping

  • klass (Class)

    class of generator

Returns:

  • (Hash)

    generator mappings



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

def add_generator(name, klass)
  mappings[name] = klass
end

.help(command = 'generate') ⇒ Object

Show help message with available generators.



10
11
12
13
14
15
16
17
18
# File 'lib/adhearsion/generators.rb', line 10

def help(command = 'generate')
  "".tap do |h|
    h << "Available generators:\n"

    mappings.each_pair do |name, klass|
      h << "* " << klass.desc << "\n"
    end
  end
end

.invoke(generator_name, args = ARGV) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/adhearsion/generators.rb', line 20

def invoke(generator_name, args = ARGV)
  klass = Generators.mappings[generator_name.to_sym]
  raise CLI::UnknownGeneratorError, generator_name unless klass

  args << "--help" if args.empty? && klass.arguments.any?(&:required?)

  klass.start args
end

.mappingsObject

Return a ordered list of task with their class



32
33
34
# File 'lib/adhearsion/generators.rb', line 32

def mappings
  @_mappings ||= Hash.new
end