Class: Jack::Config::YamlFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/jack/config/yaml_formatter.rb

Overview

Class does very specific formatting for the eb config files:

* Makes sure that the keys are sorted so we can compare them
* It also scripts out the generated DateModified and DateCreated Metadata

Instance Method Summary collapse

Instance Method Details

#process(file) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/jack/config/yaml_formatter.rb', line 10

def process(file)
  data = YAML.load_file(file)
  data = (data)
  dump = YAML.dump(data).gsub("!ruby/object:Hash", '')
  lines = dump.split("\n")
  lines = lines.map { |l| l.rstrip } # strip trailing whitespace
  dump = lines[1..-1].join("\n") + "\n" # strip first line
  outfile = "#{file}.sorted"
  File.open(outfile, 'w') { |f| f.write(dump) }
  FileUtils.mv(outfile, file)
end

#strip_metadata_dates(data) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/jack/config/yaml_formatter.rb', line 22

def (data)
   = data['EnvironmentConfigurationMetadata']
  if 
    .delete('DateModified')
    .delete('DateCreated')
  end
  data
end