class StructureButcher::Storer

Public Instance Methods

save_structure(structure, filename, format) click to toggle source
# File lib/structurebutcher.rb, line 206
def save_structure(structure, filename, format)
    sorted_structure = {}
    structure.keys.each do |key|
        value = structure[key]
        if value.is_a?(Hash)
            sorted_structure[key] = Hash[value.sort]
        else
            sorted_structure[key] = value
        end
    end
    File.write(filename, structure_in_format(Hash[sorted_structure.sort], format))
end
structure_in_format(structure, format) click to toggle source
# File lib/structurebutcher.rb, line 190
def structure_in_format(structure, format)
    case format
    when "json"
        return JSON.generate(structure)
    when "yaml"
        return structure.to_yaml
    when "properties"
        return JavaProperties.generate(structure)
    when "hocon"
        config = Hocon::ConfigFactory.parse_string(structure.to_json)
        return config.root.render(Hocon::ConfigRenderOptions.new(false, true, true, false))
    else
        throw "Unsupported format"
    end
end