lib/lograge/formatters/key_value.rb in lograge-0.9.0 vs lib/lograge/formatters/key_value.rb in lograge-0.10.0

- old
+ new

@@ -1,29 +1,31 @@ module Lograge module Formatters class KeyValue def call(data) - fields = fields_to_display(data) - - event = fields.map { |key| format(key, data[key]) } - event.join(' ') + fields_to_display(data) + .map { |key| format(key, data[key]) } + .join(' ') end + protected + def fields_to_display(data) data.keys end def format(key, value) - if key == :error - # Exactly preserve the previous output - # Parsing this can be ambigious if the error messages contains - # a single quote - value = "'#{value}'" - elsif value.is_a? Float - value = Kernel.format('%.2f', value) - end + "#{key}=#{parse_value(key, value)}" + end - "#{key}=#{value}" + def parse_value(key, value) + # Exactly preserve the previous output + # Parsing this can be ambigious if the error messages contains + # a single quote + return "'#{value}'" if key == :error + return Kernel.format('%.2f', value) if value.is_a? Float + + value end end end end