Sha256: 19b40180f4a3df3ee60e385017bba85330694428d5c0cb8918d4f6231204c5e6
Contents?: true
Size: 701 Bytes
Versions: 2
Compression:
Stored size: 701 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 # @param [Symbol, String] id_attribute The attribute to use as the id. 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
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
honeybadger-5.3.0 | vendor/bundle/ruby/3.2.0/gems/lumberjack-1.2.9/lib/lumberjack/formatter/id_formatter.rb |
lumberjack-1.2.9 | lib/lumberjack/formatter/id_formatter.rb |