Class: Lightning::Generator
- Inherits:
-
Object
- Object
- Lightning::Generator
- 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
- - (Object) underling readonly Object used to call generator(s).
Class Method Summary
- + (Hash) generators Maps generators to their descriptions.
- + (Object) load_plugins Loads default and user generator plugins.
- + (Object) run(gens = [], options = {}) Runs generators.
Instance Method Summary
- - (Generator) initialize constructor A new instance of Generator.
- - (nil, true) run(gens, options) Main method which runs generators.
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
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
20 21 22 23 24 25 |
# File 'lib/lightning/generator.rb', line 20 def self.run(gens=[], ={}) load_plugins new.run(gens, ) rescue $stderr.puts "Error: #{$!.message}" end |
Instance Method Details
- (nil, true) run(gens, options)
Main method which runs generators
43 44 45 46 47 48 49 50 51 |
# File 'lib/lightning/generator.rb', line 43 def run(gens, ) if .key?(:once) run_once(gens, ) else gens = DEFAULT_GENERATORS if Array(gens).empty? gens = Hash[*gens.zip(gens).flatten] if gens.is_a?(Array) generate_bolts gens end end |