Class: SimpleTemplater::GeneratorSet
- Inherits:
-
Object
- Object
- SimpleTemplater::GeneratorSet
- Defined in:
- lib/simple-templater/generator_set.rb
Overview
one project can has a generator in system gems and in ~/.rango/stubs/project, and these two generators are one generator set
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Instance Method Summary collapse
- #custom ⇒ Object
- #generators ⇒ Object
-
#initialize(name, *paths) ⇒ GeneratorSet
constructor
A new instance of GeneratorSet.
- #run(args = ARGV) ⇒ Object
Constructor Details
#initialize(name, *paths) ⇒ GeneratorSet
Returns a new instance of GeneratorSet.
12 13 14 15 16 17 18 19 |
# File 'lib/simple-templater/generator_set.rb', line 12 def initialize(name, *paths) @name = name.to_sym @paths = check_paths(paths) if File.directory?(self.custom) puts "Added custom generator from #{self.custom}" @paths.unshift(self.custom) end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/simple-templater/generator_set.rb', line 11 def name @name end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
11 12 13 |
# File 'lib/simple-templater/generator_set.rb', line 11 def paths @paths end |
Instance Method Details
#custom ⇒ Object
21 22 23 |
# File 'lib/simple-templater/generator_set.rb', line 21 def custom File.join(ENV["HOME"], ".simple-templater", self.name.to_s) end |
#generators ⇒ Object
25 26 27 |
# File 'lib/simple-templater/generator_set.rb', line 25 def generators @generators ||= self.paths.map { |path| Generator.new(self.name, path) } end |
#run(args = ARGV) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/simple-templater/generator_set.rb', line 29 def run(args = ARGV) full = self.generators.find { |generator| generator.full? } diff = self.generators.find { |generator| not generator.full? } raise GeneratorNotFound, "Generator set #{self.inspect} hasn't any full generator" if full.nil? full.run(args) diff.run(args) unless diff.nil? end |