Sha256: 23783759bfe98755cbe4703610083ae2c23653134a73f6f2be8c8c34c63c8ca5

Contents?: true

Size: 1.29 KB

Versions: 18

Compression:

Stored size: 1.29 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')
        "".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#class << self
  end#module
end#module

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
adhearsion-2.4.0 lib/adhearsion/generators.rb
adhearsion-2.4.0.beta3 lib/adhearsion/generators.rb
adhearsion-2.4.0.beta2 lib/adhearsion/generators.rb
adhearsion-2.4.0.beta1 lib/adhearsion/generators.rb
adhearsion-2.3.5 lib/adhearsion/generators.rb
adhearsion-2.3.4 lib/adhearsion/generators.rb
adhearsion-2.3.3 lib/adhearsion/generators.rb
adhearsion-2.3.2 lib/adhearsion/generators.rb
adhearsion-2.3.1 lib/adhearsion/generators.rb
adhearsion-2.3.0 lib/adhearsion/generators.rb
adhearsion-2.2.1 lib/adhearsion/generators.rb
adhearsion-2.2.0 lib/adhearsion/generators.rb
adhearsion-2.1.3 lib/adhearsion/generators.rb
adhearsion-2.1.2 lib/adhearsion/generators.rb
adhearsion-2.1.1 lib/adhearsion/generators.rb
adhearsion-2.1.0 lib/adhearsion/generators.rb
adhearsion-2.0.1 lib/adhearsion/generators.rb
adhearsion-2.0.0 lib/adhearsion/generators.rb