Class: Lightning::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/generator.rb

Overview

Generates globs for bolts using methods defined in Generators. Generated bolts are inserted under Lightning.config[:bolts]. Users can define their own generators with generator plugins.

Constant Summary

DEFAULT_GENERATORS =
%w{gem ruby local_ruby wild}

Instance Attribute Summary

Class Method Summary

Instance Method Summary

Constructor Details

- (Generator) initialize

A new instance of Generator



38
39
40
# File 'lib/lightning/generator.rb', line 38

def initialize
  @underling = Object.new.extend(Generators)
end

Instance Attribute Details

- (Object) underling (readonly)

Object used to call generator(s)



37
38
39
# File 'lib/lightning/generator.rb', line 37

def underling
  @underling
end

Class Method Details

+ (Hash) generators

Maps generators to their descriptions

Returns:

  • (Hash) — Maps generators to their descriptions


9
10
11
12
# File 'lib/lightning/generator.rb', line 9

def self.generators
  load_plugins
  Generators.generators
end

+ (Object) load_plugins

Loads default and user generator plugins



28
29
30
31
32
33
34
# File 'lib/lightning/generator.rb', line 28

def self.load_plugins
  @loaded ||= begin
    Util.load_plugins File.dirname(__FILE__), 'generators'
    Util.load_plugins Lightning.dir, 'generators'
    true
  end
end

+ (Object) run(gens = [], options = {})

Runs generators

Parameters:

  • (Array<String>) Generators — instance methods
  • (Hash) options (defaults to: {})

Options Hash (options):

  • (String) :once N/A — Generator to run once
  • (Boolean) :test N/A — Runs generators in test mode which only displays generated globs and doesn’t save them


20
21
22
23
24
25
# File 'lib/lightning/generator.rb', line 20

def self.run(gens=[], options={})
  load_plugins
  new.run(gens, options)
rescue
  $stderr.puts "Error: #{$!.message}"
end

Instance Method Details

- (nil, true) run(gens, options)

Main method which runs generators

Returns:

  • (nil, true) — Main method which runs generators


43
44
45
46
47
48
49
50
51
# File 'lib/lightning/generator.rb', line 43

def run(gens, options)
  if options.key?(:once)
    run_once(gens, options)
  else
    gens = DEFAULT_GENERATORS if Array(gens).empty?
    gens = Hash[*gens.zip(gens).flatten] if gens.is_a?(Array)
    generate_bolts gens
  end
end