module TomlRB::Dumper::SortFixPatch
NOTE:
- dumper sorts settins keys as a collection of string or symbols only - settings values like { a: 1, 'b' => 2 } will fail on comparison errors (Symbol with String) - problem is located in TomlRB::Dumper#sort_pairs(hash) method - problem code: `hash.keys.sort.map` (failed on `.sort` part) - we can patch this code by explicit `.map(&:to_s)` before `.sort`
@api private @since 0.12.0
Private Instance Methods
fixed_keys_sort(hash)
click to toggle source
NOTE: our fix (for detales see notes above)
# File lib/qonfig/plugins/toml/tomlrb_fixes.rb, line 39 def fixed_keys_sort(hash) hash.keys.sort_by(&:to_s) end
sort_pairs(hash)
click to toggle source
NOTE: target method for our fix
# File lib/qonfig/plugins/toml/tomlrb_fixes.rb, line 16 def sort_pairs(hash) nested_pairs = [] simple_pairs = [] table_array_pairs = [] # NOTE: our fix (original code: `hash.keys.sort`) (for details see notes above) fixed_keys_sort(hash).each do |key| val = hash[key] element = [key, val] if val.is_a? Hash nested_pairs << element elsif val.is_a?(Array) && val.first.is_a?(Hash) table_array_pairs << element else simple_pairs << element end end [simple_pairs, nested_pairs, table_array_pairs] end