Skip to content

Commit

Permalink
Correct subnested objects parsing for sli_specification
Browse files Browse the repository at this point in the history
  • Loading branch information
kaarolch committed May 24, 2024
1 parent 3a00b85 commit d3370b6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/kennel/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,14 @@ def pretty_print(hash)

sort_hash(hash).map do |k, v|
pretty_value =
if v.is_a?(Hash) || (v.is_a?(Array) && !v.all? { |e| e.is_a?(String) })
if k == :sli_specification && v.is_a?(Hash)
formatted_sli_specification = JSON.pretty_generate(v)
.gsub(": null", "=> nil") # Convert JSON null to Ruby nil
.gsub(/"([^"]+)":\s*/, '\1 => ') # Convert JSON keys to Ruby hash rocket syntax
.gsub(/^/, " ") # Indent
formatted_sli_specification = convert_strings_to_heredoc(formatted_sli_specification)
"\n#{formatted_sli_specification}\n "
elsif v.is_a?(Hash) || (v.is_a?(Array) && !v.all? { |e| e.is_a?(String) })
# update answer here when changing https://stackoverflow.com/questions/8842546/best-way-to-pretty-print-a-hash
# (exclude last indent gsub)
pretty = JSON.pretty_generate(v)
Expand Down

0 comments on commit d3370b6

Please sign in to comment.