Class: SimpleTemplater::GeneratorSet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/simple-templater/generator_set.rb', line 11

def name
  @name
end

#pathsObject (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

#customObject



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

#generatorsObject



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

Raises:

  • (GeneratorNotFound)


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