Sha256: e35b103e21e9d2ff2317370695e0c5c4963ea28cc3d011dc2938fddbc0a09993

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

# encoding: utf-8

require 'adhearsion/generators/generator'

module Adhearsion
  module Generators
    class << self

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

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

      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

      #
      # 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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
adhearsion-2.6.4 lib/adhearsion/generators.rb
adhearsion-2.6.3 lib/adhearsion/generators.rb
adhearsion-3.0.0.rc1 lib/adhearsion/generators.rb
adhearsion-3.0.0.beta2 lib/adhearsion/generators.rb
adhearsion-3.0.0.beta1 lib/adhearsion/generators.rb
adhearsion-2.6.2 lib/adhearsion/generators.rb
adhearsion-2.6.1 lib/adhearsion/generators.rb
adhearsion-2.6.0 lib/adhearsion/generators.rb