Class: Lumberjack::Formatter::IdFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::IdFormatter
- Defined in:
- lib/lumberjack/formatter/id_formatter.rb
Overview
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.
Instance Method Summary collapse
- #call(obj) ⇒ Object
-
#initialize(id_attribute = :id) ⇒ IdFormatter
constructor
A new instance of IdFormatter.
Constructor Details
#initialize(id_attribute = :id) ⇒ IdFormatter
Returns a new instance of IdFormatter.
9 10 11 |
# File 'lib/lumberjack/formatter/id_formatter.rb', line 9 def initialize(id_attribute = :id) @id_attribute = id_attribute end |
Instance Method Details
#call(obj) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/lumberjack/formatter/id_formatter.rb', line 13 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 |