Class: Lumberjack::Formatter::StructuredFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::StructuredFormatter
- Defined in:
- lib/lumberjack/formatter/structured_formatter.rb
Overview
Dereference arrays and hashes and recursively call formatters on each element. This formatter provides deep traversal of nested data structures, applying formatting to all contained elements while handling circular references safely.
The StructuredFormatter is essential for formatting complex nested objects like configuration hashes, API responses, or any hierarchical data structures that need consistent formatting throughout their entire structure.
Defined Under Namespace
Classes: RecusiveReferenceError
Instance Method Summary collapse
-
#call(obj) ⇒ Object
Format a structured object by recursively processing all nested elements.
-
#initialize(formatter = nil) ⇒ StructuredFormatter
constructor
A new instance of StructuredFormatter.
Constructor Details
#initialize(formatter = nil) ⇒ StructuredFormatter
Returns a new instance of StructuredFormatter.
24 25 26 |
# File 'lib/lumberjack/formatter/structured_formatter.rb', line 24 def initialize(formatter = nil) @formatter = formatter end |
Instance Method Details
#call(obj) ⇒ Object
Format a structured object by recursively processing all nested elements.
33 34 35 |
# File 'lib/lumberjack/formatter/structured_formatter.rb', line 33 def call(obj) call_with_references(obj, Set.new) end |