class Jack::Config::YamlFormatter

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

Public Instance Methods

process(file) click to toggle source
# File lib/jack/config/yaml_formatter.rb, line 10
def process(file)
  data = YAML.load_file(file)
  data = sort_top_level_keys(data)
  data = strip_metadata_dates(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
sort_top_level_keys(data) click to toggle source
# File lib/jack/config/yaml_formatter.rb, line 32
def sort_top_level_keys(data)
  data.keys.sort.inject({}) do |result, k|
    result[k] = data[k]
    result
  end
end
strip_metadata_dates(data) click to toggle source
# File lib/jack/config/yaml_formatter.rb, line 23
def strip_metadata_dates(data)
  metadata = data['EnvironmentConfigurationMetadata']
  if metadata
    metadata.delete('DateModified')
    metadata.delete('DateCreated')
  end
  data
end