Sha256: a426d619d2609a069c96ecebc51f64ee64059be6ea92982907def123dfa5fd12

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8
require "erb"
require "pathname"

module Antelope

  # Contains the classes that generate parsers.  This contains a
  # registery of all of the generators available to antelope.
  module Generator

    # Returns a hash of all of the generators registered within this
    # module.  If a generator is accessed that does not exist on the
    # hash, it by default returns the {Generator::Null} class.
    #
    # @return [Hash<(Symbol, String) => Generator::Base>]
    def generators
      @_generators ||= Hash.new { |h, k| h[k] = Generator::Null }
    end

    # Registers a generator with the given names.  If multiple names
    # are given, they are assigned the generator as a value in the
    # {#generators} hash; otherwise, the one name is assigned the
    # generator as a value.
    #
    # @param generator [Generator::Base] the generator class to
    #   associate the key with.
    # @param name [String, Symbol] a name to associate the generator
    #   with.
    def register_generator(generator, *names)
      names = [names].flatten
      raise ArgumentError,
        "Requires at least one name" unless names.any?
      raise ArgumentError,
        "All name values must be a Symbol or string" unless names.
        all? {|_| [Symbol, String].include?(_.class) }

      names.each do |name|
        generators[name] = generator
      end
    end

    extend self

  end
end

require "antelope/generator/base"
require "antelope/generator/group"
require "antelope/generator/output"
require "antelope/generator/ruby"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
antelope-0.1.8 lib/antelope/generator.rb