Class: Ferrum::Log::Default
- Inherits:
-
Object
- Object
- Ferrum::Log::Default
- Includes:
- Paint
- Defined in:
- lib/ferrum/log/default.rb,
sig/ferrum/log/default.rbs
Overview
Formats CDP messages as Ferrum always has: the direction, the elapsed time and the message as JSON. On a terminal the arrow is colored by kind, the time dimmed and the method bold.
Constant Summary
Constants included from Paint
Instance Method Summary collapse
-
#initialize(color: false) ⇒ Default
constructor
A new instance of Default.
- #received(message, raw, elapsed, _command = nil) ⇒ String
- #sent(message, elapsed) ⇒ String
Methods included from Paint
Constructor Details
#initialize(color: false) ⇒ Default
Returns a new instance of Default.
15 16 17 |
# File 'lib/ferrum/log/default.rb', line 15 def initialize(color: false) @color = color end |
Instance Method Details
#received(message, raw, elapsed, _command = nil) ⇒ String
35 36 37 38 39 40 41 42 43 |
# File 'lib/ferrum/log/default.rb', line 35 def received(, raw, elapsed, _command = nil) arrow = if .nil? || !.key?("id") then :magenta elsif .key?("error") then :red else :green end body = ? payload(, ["method"]) : raw " #{paint('◀', arrow)} #{paint(elapsed, :dim)} #{body}\n" end |
#sent(message, elapsed) ⇒ String
24 25 26 |
# File 'lib/ferrum/log/default.rb', line 24 def sent(, elapsed) "\n\n#{paint('▶', :cyan)} #{paint(elapsed, :dim)} #{payload(, [:method])}" end |