Sha256: e2e8056ab8b5a41ffdac41eff44e818972c75985a0d9fedd90b8f2a9e0e3952b
Contents?: true
Size: 632 Bytes
Versions: 10
Compression:
Stored size: 632 Bytes
Contents
# frozen_string_literals: true module Lumberjack class Formatter # Format an object that has an id as a hash with keys for class and id. This formatter is useful # as a default formatter for objects pulled from a data store. By default it will use :id as the # id attribute. class IdFormatter def initialize(id_attribute = :id) @id_attribute = id_attribute end def call(obj) if obj.respond_to?(@id_attribute) id = obj.send(@id_attribute) { "class" => obj.class.name, "id" => id } else obj.to_s end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems