Module: TTY::Config::Generator Private

Defined in:
lib/tty/config/generator.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Responsible for converting a data object into content in INI format

Class Method Summary collapse

Class Method Details

.generate(data, separator: "=") ⇒ String

Generate file content based on the data hash

Examples:

generate({"foo" => {"bar" => "baz"}})
# => "[foo]\nbar = baz\n"

Parameters:

  • data (Hash{String => Object})

    the data to convert to INI file format

  • separator (String) (defaults to: "=")

    the separator for the key and value pairs

Returns:

  • (String)

    the INI file content



24
25
26
27
28
29
30
31
32
33
# File 'lib/tty/config/generator.rb', line 24

def self.generate(data, separator: "=")
  sections_and_values = group_into_sections_and_values(data)

  values = generate_values(sections_and_values[:values], separator)
  values << "" unless values.empty?
  sections = generate_sections(sections_and_values[:sections], separator)

  content = values + sections
  content.join("\n")
end