-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert nil to empty string #28
Conversation
Can you please show where in the spec we should expect |
My interpretation of toml-lang/toml#30 is that a key with a nil value should not be present, my rational is that if it's present it should be handled rather than the current error and Perhaps a better solution would be: other_pairs.each do |pair|
key, val = pair
if key.include? '.'
raise SyntaxError, "Periods are not allowed in keys (failed on key: #{key.inspect})"
end
unless val.nil?
@body += "#{key} = #{format(val)}\n"
end
end at https://github.com/jm/toml/blob/master/lib/toml/generator.rb#L54 |
>> if nil
.. print "whee"
.. end
# nothing prints
>> if ""
.. print "whee"
.. end
"whee"
In toml-lang/toml#30, it looks like mojombo decided a key with no value should be an empty hash table, so we should set the value for keys without any value to be an empty hash table. |
Agreed, I should have qualified my statement to be limited for uses as configuration where often
It was said that an empty key group should be an empty hash table. This term is defined in v0.1.0 and redefined as My following of the thread is still that a key with no value is omitted. I've updated my PR to handle these. require 'toml'
hash = {
"bar" => nil,
"foo" => {}
}
doc = TOML::Generator.new(hash).body
# => "\n[foo]\n" |
Ok, cool. Thanks! 👍 Can you please write a quick test for this? Thank you! |
I've added the empty table and a |
Awesome! LGTM. @jm? |
👍 Looks good to me! |
Currently if a key's value is
nil
when usingTOML::Generator.new(hash).body
a undefined method error is thrown:NoMethodError: undefined method 'to_toml' for nil:NilClass
This PR converts supports
nil.to_toml
by converting it into an empty string.