Module: Bauk::Gen::Init

Includes:
Utils::Log
Included in:
Generator
Defined in:
lib/bauk/gen/init.rb

Overview

Class purely used for init

Instance Method Summary collapse

Instance Method Details

#initObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bauk/gen/init.rb', line 12

def init
  FileUtils.mkdir_p '.bauk/generator'
  init_templates.each do |file,content|
    file = ".bauk/generator/templates/#{name}/#{file}"
    FileUtils.mkdir_p File.dirname(file.to_s)
    File.write(file.to_s, content)
  end
  init_files.each do |file,content|
    FileUtils.mkdir_p File.dirname(file.to_s)
    File.write(file.to_s, content)
  end
  init_config_file
end

#init_config_fileObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bauk/gen/init.rb', line 42

def init_config_file
  file = Bauk::Gen::Configs::Files.new.default_files[0]
  if File.exist? file
    log.error "File already exists: #{file}"
  else
    init_config = default_config
    unless init_config[:generators]
      init_config[:generators] = {}
      init_config[:generators][name.to_sym] = {}
    end
    File.write(file, YAML.dump(init_config))
  end
end

#init_filesObject



26
27
28
# File 'lib/bauk/gen/init.rb', line 26

def init_files
  {}
end

#init_templatesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bauk/gen/init.rb', line 30

def init_templates
  {
    'exampleGenerated/example..erb': <<~FILE
      <%= name %>
    FILE,
    'example_generated..erb': <<~FILE
      Name: <%= name %>
      Description: <%= description %>
    FILE
  }
end