Module: Antelope::Generator

Extended by:
Generator
Included in:
Generator, Group
Defined in:
lib/antelope/generator.rb,
lib/antelope/generator/base.rb,
lib/antelope/generator/null.rb,
lib/antelope/generator/ruby.rb,
lib/antelope/generator/group.rb,
lib/antelope/generator/output.rb

Overview

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

Defined Under Namespace

Classes: Base, Group, Null, Output, Ruby

Instance Method Summary collapse

Instance Method Details

#generatorsHash<(Symbol, String) => Generator::Base>

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 Null class.

Returns:



16
17
18
# File 'lib/antelope/generator.rb', line 16

def generators
  @_generators ||= Hash.new { |h, k| h[k] = Generator::Null }
end

#register_generator(generator, *names) ⇒ Object

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.

Parameters:

  • generator (Generator::Base)

    the generator class to associate the key with.

  • name (String, Symbol)

    a name to associate the generator with.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/antelope/generator.rb', line 29

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