class Antelope::Generator::Group

For use to use multiple generators as a bundle. Works exactly like a normal generator, i.e. responds to both {.register_as} and {#generate}, but also responds to {.register_generator}, like {Generator}. Any generators registered to the group are used to generate the files.

@abtract Subclass and use {.register_generator} to create a

group generator.

Public Class Methods

new(*_) click to toggle source

Initialize the group generator. Calls {Base#initialize}, and then instantizes all of the generators in the group.

Calls superclass method Antelope::Generator::Base::new
# File lib/antelope/generator/group.rb, line 18
def initialize(*_)
  super

  generators.map! do |gen|
    gen.new(*_)
  end
end

Public Instance Methods

generate() click to toggle source

Generates files using the generators contained within this group. If it encounters an error in one of the generators, it will continue to try to generate the rest of the generators. It will then raise the last error given at the end.

@return [void]

# File lib/antelope/generator/group.rb, line 32
def generate
  error = nil
  generators.map do |gen|
    begin
      gen.generate
    rescue => e
      puts "Error running #{gen.class}: #{e.message}"
      error = e
    rescue SyntaxError => e
      puts "Error running #{gen.class}: #{e.message}"
      error = e
    end
  end

  raise error if error
end

Private Instance Methods

generators() click to toggle source

Retrieve a list of all of the generators that are contained within this group.

@return [Array<Generator::Base>]

# File lib/antelope/generator/group.rb, line 55
def generators
  @_generators ||= self.class.generators.values
end