class Logged::Formatter::KeyValue

Key-Value formatter for logged

Public Instance Methods

call(data) click to toggle source
# File lib/logged/formatter/key_value.rb, line 9
def call(data)
  data
    .reject { |_k, v| v.nil? || (v.is_a?(String) && v.blank?) }
    .map { |k, v| format_key(k, v) }
    .join(' ')
end
format_key(key, value) click to toggle source
# File lib/logged/formatter/key_value.rb, line 16
def format_key(key, value)
  # encapsulate in single quotes if value is a string
  value = "'#{value}'" if value.is_a?(String)

  # ensure only two decimals
  value = Kernel.format('%.2f', value) if value.is_a?(Float)

  "#{key}=#{value}"
end