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. Users can define their own generators with generator plugins.
Constant Summary collapse
- DEFAULT_GENERATORS =
%w{gem ruby local_ruby wild}
Instance Attribute Summary collapse
-
#underling ⇒ Object
readonly
Object used to call generator(s).
Class Method Summary collapse
-
.generators ⇒ Hash
Maps generators to their descriptions.
-
.load_plugins ⇒ Object
Loads default and user generator plugins.
-
.run(gens = [], options = {}) ⇒ Object
Runs generators.
Instance Method Summary collapse
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
-
#run(gens, options) ⇒ nil, true
Main method which runs generators.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
39 40 41 |
# File 'lib/lightning/generator.rb', line 39 def initialize @underling = Object.new.extend(Generators) end |
Instance Attribute Details
#underling ⇒ Object (readonly)
Object used to call generator(s)
38 39 40 |
# File 'lib/lightning/generator.rb', line 38 def underling @underling end |
Class Method Details
.generators ⇒ Hash
Returns Maps generators to their descriptions.
9 10 11 12 |
# File 'lib/lightning/generator.rb', line 9 def self.generators load_plugins Generators.generators end |
.load_plugins ⇒ Object
Loads default and user generator plugins
29 30 31 32 33 34 35 |
# File 'lib/lightning/generator.rb', line 29 def self.load_plugins @loaded ||= begin Util.load_plugins File.dirname(__FILE__), 'generators' Util.load_plugins Lightning.dir, 'generators' true end end |
.run(gens = [], options = {}) ⇒ Object
Runs generators
21 22 23 24 25 26 |
# File 'lib/lightning/generator.rb', line 21 def self.run(gens=[], ={}) load_plugins new.run(gens, ) rescue $stderr.puts "Error: #{$!.}" end |
Instance Method Details
#run(gens, options) ⇒ nil, true
Returns Main method which runs generators.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lightning/generator.rb', line 44 def run(gens, ) if .key?(:once) run_once(gens, ) elsif .key?(:live) Array(call_generator(gens, false)) else gens = DEFAULT_GENERATORS if Array(gens).empty? gens = Hash[*gens.zip(gens).flatten] if gens.is_a?(Array) generate_bolts gens end end |