Module: AmazingTap
- Defined in:
- lib/amazing_tap.rb,
lib/amazing_tap/version.rb,
sig/amazing_tap.rbs
Defined Under Namespace
Modules: ObjectExtension Classes: Error
Constant Summary collapse
- DEFAULT_CLOSING_THRESHOLD =
24- RECEIVER_PATTERN =
/([\w@$.\[\]!?]+)\s*\.\s*tap(?:p|ap)\b/- VERSION =
"0.1.2"
Class Attribute Summary collapse
Class Method Summary collapse
-
.infer_label(location) ⇒ String?
Extracts the receiver expression preceding .tapp/.tapap on the call-site line, e.g.
-
.print_labeled(object, label, callers:, type: true, backtrace: false) ⇒ void
Prints a header line (label and/or class) followed by the ap-formatted object, then optional caller frames.
Class Attribute Details
.closing_threshold ⇒ Object
19 20 21 |
# File 'lib/amazing_tap.rb', line 19 def closing_threshold @closing_threshold ||= DEFAULT_CLOSING_THRESHOLD end |
.show_type ⇒ Object
29 30 31 |
# File 'lib/amazing_tap.rb', line 29 def show_type @show_type.nil? ? true : @show_type end |
Class Method Details
.infer_label(location) ⇒ String?
Extracts the receiver expression preceding .tapp/.tapap on the call-site
line, e.g. "user" for user.tapp or "account.owner" for
account.owner.tapp. Inference is textual: literals, parenthesized
calls, multiline chains, or unreadable sources (eval, REPL) yield nil.
40 41 42 43 44 45 46 |
# File 'lib/amazing_tap.rb', line 40 def infer_label(location) path = location.path return nil unless path && File.readable?(path) line = File.readlines(path)[location.lineno - 1] line && line[RECEIVER_PATTERN, 1] end |
.print_labeled(object, label, callers:, type: true, backtrace: false) ⇒ void
This method returns an undefined value.
Prints a header line (label and/or class) followed by the ap-formatted object, then optional caller frames. Output longer than .closing_threshold lines is closed with a "/label" line so long dumps stay identifiable. Colorized under the same conditions amazing_print colorizes its output.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/amazing_tap.rb', line 62 def print_labeled(object, label, callers:, type: true, backtrace: false) colorize = AmazingPrint::Inspector.new.colorize? header = [] header << (colorize ? AmazingPrint::Colors.yellow(label.to_s) : label.to_s) if label if type type_text = "(#{object.class})" header << (colorize ? AmazingPrint::Colors.whiteish(type_text) : type_text) end puts header.join(" ") unless header.empty? body = object.ai puts body frames = backtrace == true ? callers : callers.first(backtrace || 0) frames.each { |frame| puts " from #{frame}" } return unless label && body.lines.length + frames.length > closing_threshold closing = "/#{label}" puts colorize ? AmazingPrint::Colors.yellow(closing) : closing end |