Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/toml/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ def visit(hash, path = "")
if key.include? '.'
raise SyntaxError, "Periods are not allowed in keys (failed on key: #{key.inspect})"
end
@body += "#{key} = #{format(val)}\n"
unless val.nil?
@body += "#{key} = #{format(val)}\n"
end
end
@body += "\n" unless other_pairs.empty?

# Then deal with sub-hashes
hash_pairs.each do |pair|
key, hash = pair
visit(hash, (path.empty? ? key : [path, key].join(".")))
if hash.empty?
@body += "[#{path.empty? ? key : [path, key].join(".")}]\n"
else
visit(hash, (path.empty? ? key : [path, key].join(".")))
end
end
end#visit

Expand Down
9 changes: 7 additions & 2 deletions test/test_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def setup
"key" => {
"group" => {
"value" => "lol"
}
},
"nil_table" => {}
},
"date" => DateTime.now
"date" => DateTime.now,
"nil" => nil
}

end
Expand All @@ -34,6 +36,9 @@ def test_generator
original_date = doc.delete "date"
parsed_date = doc_parsed.delete "date"

# removing the nil value
remove_nil = doc.delete "nil"

assert_equal doc, doc_parsed
assert_equal original_date.to_time.to_s, parsed_date.to_time.to_s
end
Expand Down