Class: Elevage::Generate

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/elevage/generate.rb

Overview

Create new environment desired state files from platform template

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



9
10
11
# File 'lib/elevage/generate.rb', line 9

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#create_environmentObject

Process the ‘generate` command to create a new environment file



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elevage/generate.rb', line 16

def create_environment
  fail IOError, ERR[:env_exists] if File.file?(ENV_FOLDER + env + '.yml')
  platform = Elevage::Platform.new
  platformfile = File.open(YML_PLATFORM, 'r')
  # TODO: The things from here forward I would rather have in the template
  # file but that is even uglier, trying to get formatting correct
  # will need to investigate some POWER erb skills to clean this up
  @env_pools = ''
  @env_components = ''
  line = ''
  line = platformfile.gets until line =~ /pools/
  platform.pools.each do |k, _v|
    line = platformfile.gets until line.include?(k)
    @env_pools += line
    next_line = platformfile.gets
    @env_pools += "#{next_line}" if next_line.include?('<<')
    @env_pools += "      network:\n\n"
  end
  line = platformfile.gets until line =~ /components/
  platform.components.each do |k, v|
    line = platformfile.gets until line.include?(k)
    @env_components += line
    next_line = platformfile.gets
    @env_components += "#{next_line}" if next_line.include?('<<')
    @env_components += "      addresses:\n"
    (1..v['count']).each { @env_components += "        -\n" }
    @env_components += "\n"
  end
  template(TEMPLATE_ENV, ENV_FOLDER + env + '.yml')
  puts "#{env}.yml added in environments folder"
end