Module: Antelope::Generator
- Extended by:
- Generator
- Defined in:
- lib/antelope/generator.rb,
lib/antelope/generator/c.rb,
lib/antelope/generator/base.rb,
lib/antelope/generator/html.rb,
lib/antelope/generator/info.rb,
lib/antelope/generator/null.rb,
lib/antelope/generator/ruby.rb,
lib/antelope/generator/error.rb,
lib/antelope/generator/group.rb,
lib/antelope/generator/output.rb,
lib/antelope/generator/c_header.rb,
lib/antelope/generator/c_source.rb,
lib/antelope/generator/base/extra.rb,
lib/antelope/generator/base/coerce.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, C, CHeader, CSource, Error, Group, HTML, Info, Null, Output, Ruby
Instance Method Summary collapse
-
#directives ⇒ Hash
Returns a hash of all of the directives that are available in the generators of this module.
-
#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
#directives ⇒ Hash
Returns a hash of all of the directives that are available in the generators of this module.
24 25 26 27 |
# File 'lib/antelope/generator.rb', line 24 def directives generators.values.map(&:directives). inject({}, :merge) end |
#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.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/antelope/generator.rb', line 38 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.to_s.downcase] = generator end end |