Class: Toycol::TemplateGenerator

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/toycol/template_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helper

#logger

Constructor Details

#initialize(name, type) ⇒ TemplateGenerator

Returns a new instance of TemplateGenerator.



26
27
28
29
# File 'lib/toycol/template_generator.rb', line 26

def initialize(name, type)
  @name = name
  @type = type
end

Class Method Details

.generate!(type:, name:) ⇒ Object

Raises:



8
9
10
11
12
13
14
15
16
17
# File 'lib/toycol/template_generator.rb', line 8

def generate!(type:, name:)
  raise Error, "Unknown Type: This type of template can't be generated" unless valid? type

  if type == "all"
    new(name, "protocol").generate!
    new(name, "app").generate!
  else
    new(name, type).generate!
  end
end

Instance Method Details

#generate!Object

Raises:



31
32
33
34
35
36
# File 'lib/toycol/template_generator.rb', line 31

def generate!
  raise Error, "#{filename} already exists" unless Dir.glob(filename).empty?

  File.open(filename, "w") { |f| f.print template_text_for_new }
  logger "Generate #{filename} in #{FileUtils.pwd}"
end