Module: PropertyGenerator

Included in:
Generator
Defined in:
lib/linter/linter.rb,
lib/linter/report.rb,
lib/helpers/helpers.rb,
lib/generator/config.rb,
lib/generator/globals.rb,
lib/generator/service.rb,
lib/generator/generator.rb,
lib/linter/config_linter.rb,
lib/linter/globals_linter.rb,
lib/linter/services_linter.rb

Defined Under Namespace

Classes: Config, ConfigLinter, Generator, Globals, GlobalsLinter, Linter, Report, Service, ServicesLinter

Class Method Summary collapse

Class Method Details

.get_list_of_files(path, ignore_list) ⇒ Object



15
16
17
18
19
# File 'lib/helpers/helpers.rb', line 15

def get_list_of_files(path, ignore_list)
  #Returns a list of files in given path
  #Ignores files in a given ignore list
  Dir.glob(path + "/**/*").select{ |e| File.file? e unless ignore_list.include?(e.split('/')[(e.split('/')).length - 1])}
end

.invalid_paths(path, ignore_list) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/helpers/helpers.rb', line 35

def invalid_paths(path, ignore_list)
  invalid_paths = []
  list_of_file_paths = get_list_of_files(path, ignore_list)
  list_of_file_paths.each do |file_path|
    begin
      YAML.load_file(file_path)
    rescue
      invalid_paths << file_path
    end
  end
  invalid_paths
end

.read_services(path) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/helpers/helpers.rb', line 48

def read_services(path)
  Dir.glob("#{path}/services/*.{yaml,yml}").each_with_object({}) do |file, acc|
    name = File.basename(file)[/(?<service>.*)\.ya?ml$/, :service]
    path = File.absolute_path(file)
    acc[name] = path
  end
end

.sync(region, account, bucket, file, file_region) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/helpers/helpers.rb', line 71

def sync(region, , bucket, file, file_region)
  s3 = Aws::S3::Resource.new(region: region)
  filename = file.split("/").last
  puts "Destination: #{}/#{file_region}/#{filename}"
  puts "Uploading: #{file}"
  obj = s3.bucket(bucket).object("#{}/#{file_region}/#{filename}")
  obj.upload_file(file)
end

.test_runner(object, test_list) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/helpers/helpers.rb', line 7

def test_runner(object, test_list)
  results = {}
  test_list.each do |test|
    results[test] = object.send(test)
  end
  results
end

.valid_paths(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/helpers/helpers.rb', line 21

def valid_paths(path)
  valid_paths = []
  list_of_file_paths = get_list_of_files(path, [])
  list_of_file_paths.each do |file_path|
    begin
      YAML.load_file(file_path)
      valid_paths << file_path
    rescue
      next
    end
  end
  valid_paths
end

.writer(service_name, finalized, configs, output_path) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/helpers/helpers.rb', line 56

def writer(service_name, finalized, configs, output_path)
  output = []
  envs = configs.environments
  environmental_configs =  configs.environment_configs
  envs.each do | env|
     = environmental_configs[env]["account"]
    region = environmental_configs[env]["region"]
    json = JSON.pretty_generate({"properties" => finalized[env]})
    FileUtils.mkdir_p("#{output_path}/#{}/#{region}/") unless Dir.exist?("#{output_path}/#{}/#{region}/")
    File.write("#{output_path}/#{}/#{region}/#{service_name}.json", json)
    output << "#{output_path}/#{}/#{region}/#{service_name}.json"
  end
  output
end