Class: StructureButcher::Storer

Inherits:
Object
  • Object
show all
Defined in:
lib/structurebutcher.rb

Instance Method Summary collapse

Instance Method Details

#save_structure(structure, filename, format) ⇒ Object



205
206
207
# File 'lib/structurebutcher.rb', line 205

def save_structure(structure, filename, format)
    File.write(filename, structure_in_format(structure, format))
end

#structure_in_format(structure, format) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/structurebutcher.rb', line 189

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