Class: Betterp::Output
- Inherits:
-
Object
- Object
- Betterp::Output
- Defined in:
- lib/betterp/output.rb
Overview
Transforms default output from ‘Kernel.p` into enhanced, colorized output with source filename, line number, method name, and duration when used with a block.
Constant Summary collapse
- COLORS =
i[red green yellow blue purple cyan red_b green_b yellow_b blue_b purple_b cyan_b].freeze
Instance Method Summary collapse
-
#formatted(args) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(raw, source, duration, options = {}) ⇒ Output
constructor
A new instance of Output.
Constructor Details
#initialize(raw, source, duration, options = {}) ⇒ Output
9 10 11 12 13 14 15 |
# File 'lib/betterp/output.rb', line 9 def initialize(raw, source, duration, = {}) @raw = raw @source = source @duration = duration @color = color @pretty = .fetch(:pretty, false) end |
Instance Method Details
#formatted(args) ⇒ Object
rubocop:disable Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/betterp/output.rb', line 17 def formatted(args) # rubocop:disable Metrics/MethodLength (@pretty ? args : args.map(&:inspect)).map do |arg| output = [ header, colorized_prefix, colorized_duration, highlighted(caller_code), Paintbrush.paintbrush { cyan_b '=>' }, highlighted(pretty(arg)) ].compact.join(' ').chomp "#{output}\n" end end |