Class: PropertyGenerator::Generator

Inherits:
Object
  • Object
show all
Includes:
PropertyGenerator
Defined in:
lib/generator/generator.rb

Instance Method Summary collapse

Methods included from PropertyGenerator

config_enforcer, get_list_of_files, invalid_paths, read_services, sync, test_runner, valid_paths, writer

Constructor Details

#initialize(options) ⇒ Generator

purpose: initialize globals and configs serve as a broker between tasks



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generator/generator.rb', line 13

def initialize(options)
  project_path = File.expand_path(options['project_path'])
  @configs = PropertyGenerator::Config.new(project_path)
  @globals = PropertyGenerator::Globals.new(project_path, @configs)
  @globals = @globals.globals
  @accounts = @configs.accounts

  @output_path = "#{File.expand_path(options['output'])}/properties/#{SecureRandom.hex}"
  puts "Properties will be output here #{@output_path}"
  @service_list = PropertyGenerator.read_services(project_path)
end

Instance Method Details

#_upload_files(files) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/generator/generator.rb', line 64

def _upload_files(files)
  files.each_slice(20) do |file_slice|
    file_slice.map do |file|
      Thread.new do
        yield file
      end
    end.each(&:join)
  end
end

#generateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generator/generator.rb', line 25

def generate
  output = []
  @service_list.each do |service, path|
    PropertyGenerator.config_enforcer(@configs.environment_configs)
    service_instance = PropertyGenerator::Service.new(YAML.load_file(path), @configs, @globals)
    service_instance.service
    service_instance.interpolate

    out = PropertyGenerator.writer(service, service_instance.service, @configs, @output_path, service_instance.additional_options)
    (output << out).flatten!
  end
  output
end

#upload(out, config) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/generator/generator.rb', line 39

def upload(out, config)
  upload_bucket = config['upload_bucket']
  upload_region = config['upload_region']

  if config['upload_all']
    _upload_files(out.sort) do |file|
      file_region = file.split('/')[-2]
       = file.split('/')[-3]

      PropertyGenerator.sync(upload_region, , upload_bucket, file, file_region)
    end
  else
     = config['upload_account'].strip
    unless @accounts.map { |a| a.to_s.strip }.include?()
      abort("The specified account (#{}) is not configured, please add it to config/config.yml")
    end

    upload_out = out.select { |file| file.include?() && file.include?(upload_region) }
    _upload_files(upload_out) do |file|
      file_region = file.split('/')[-2]
      PropertyGenerator.sync(upload_region, , upload_bucket, file, file_region)
    end
  end
end