Module: Antelope::Generator
- Extended by:
- Generator
- 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
-
#generators ⇒ Hash<(Symbol, String) => Generator::Base>
Returns a hash of all of the generators registered within this module.
-
#register_generator(generator, *names) ⇒ Object
Registers a generator with the given names.
Instance Method Details
#generators ⇒ Hash<(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.
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.
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 |