Sha256: da23d85905708b0ddfcb5e1161675e440e551c75975a74283a87f49cf376a14a

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# encoding: utf-8

module Adhearsion
  module Generators
    extend ActiveSupport::Autoload

    autoload :Generator

    class << self

      # Show help message with available generators.
      def help(command = 'generate')
        puts "Usage: ahn #{command} GENERATOR_NAME [args] [options]"
        puts
        puts "Please choose a generator below."
        puts

        mappings.each_pair do |name, klass|
          puts name
        end
      end

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

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

        klass.start args
      end

      ##
      # Return a ordered list of task with their class
      #
      def mappings
        @_mappings ||= Hash.new
      end

      ##
      # Globally add a new generator class to +ahn generate+
      #
      # @param [Symbol] name
      # key name for generator mapping
      # @param [Class] klass
      # class of generator
      #
      # @return [Hash] generator mappings
      #
      # @example
      # Adhearsion::Generators.add_generator :myplugin, MyPluginGenerator
      #
      def add_generator(name, klass)
        mappings[name] = klass
      end

    end#class << self
  end#module
end#module

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
adhearsion-2.0.0.rc3 lib/adhearsion/generators.rb
adhearsion-2.0.0.rc2 lib/adhearsion/generators.rb
adhearsion-2.0.0.rc1 lib/adhearsion/generators.rb