module TomlRB::Dumper::ObjectConverterFix
NOTE:
- dumper uses ultra primitive way to conver objects to toml format - dumper represents nil values as a simple strings without quots, but should not represent them at all - dumper can not validate invalid structures (for example: [1, [2,3], nil] (invalid, cuz arrays should contain values of one type))
@api private @since 0.12.0
Private Instance Methods
dump_simple_pairs(simple_pairs)
click to toggle source
NOTE: target method for our fix
# File lib/qonfig/plugins/toml/tomlrb_fixes.rb, line 57 def dump_simple_pairs(simple_pairs) simple_pairs.each do |key, val| key = quote_key(key) unless bare_key? key # NOTE: our fix (original code: `@toml_str << "#{key} = #{to_toml(val)}\n"`) fixed_toml_value_append(key, val) end end
fixed_to_toml(object)
click to toggle source
NOTE our fix
# File lib/qonfig/plugins/toml/tomlrb_fixes.rb, line 71 def fixed_to_toml(object) # NOTE: original code of #toml(obj): # if object.is_a? Time # object.strftime('%Y-%m-%dT%H:%M:%SZ') # else # object.inspect # end case object when Time, DateTime, Date object.strftime('%Y-%m-%dT%H:%M:%SZ') else # NOTE: validate result value via value parsing before dump object.inspect.tap { |value| ::TomlRB.parse("sample = #{value}") } end end
fixed_toml_value_append(key, val)
click to toggle source
NOTE: our fix
# File lib/qonfig/plugins/toml/tomlrb_fixes.rb, line 66 def fixed_toml_value_append(key, val) @toml_str << "#{key} = #{fixed_to_toml(val)}\n" unless val.nil? end