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



218
219
220
# File 'lib/structurebutcher.rb', line 218

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

#structure_in_format(structure, format) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/structurebutcher.rb', line 202

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