amazing_tap 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c4b473b57dcf521b113674ad0431d7da96e3478588e1462ad237ff256e56288
4
+ data.tar.gz: 35a26f22961d7157a546875c1620b33dafd02204326cdc3617a09cf96bc22b08
5
+ SHA512:
6
+ metadata.gz: d87b4f5bed0c1494deb79e5d3c587a92711ee3c955ea8ea054e0b0e3eacfe5a169c3d8d61e69311ebffb9b18cbebc0334ec26263a7a7b335b7f0dfb9ffa06a18
7
+ data.tar.gz: 3cafc6a035ef83800e4f5f8f8cd7f0092e6b8d04ca644418ef7fd09105114ba5dc4ab56e80e2e21074f2f26d3b7ba9738d7a787f0d2438830c4e80c4ee25919f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0] - 2026-08-08
6
+
7
+ First release as `amazing_tap`, forked from [tap_amazing_print](https://github.com/shu0115/tap_amazing_print) 0.1.1.
8
+
9
+ - `tapp` prints the receiver via amazing_print with a header line and returns it; label inferred from the receiver expression at the call site, `tapp(:label)` to set it explicitly
10
+ - Header includes the receiver's class; disable with `type: false`; class-only header when inference fails
11
+ - `backtrace: true` appends caller frames, `backtrace: N` limits to N frames
12
+ - Output longer than `AmazingTap.closing_threshold` lines (default 24, globally configurable) ends with a `/label` marker
13
+ - Header and markers colorized under the same conditions as amazing_print output
14
+ - `tapap` kept as alias of `tapp`; native `Object#tap` untouched
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at s.matsumoto0115@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 shu0115
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # amazing_tap
2
+
3
+ Labeled, chain-safe debugging built on [amazing_print](https://github.com/amazing-print/amazing_print). `tapp` pretty-prints the receiver with a label inferred from the variable it was called on, plus its class and optional caller frames, then returns the receiver unchanged. Native `Object#tap` is not touched.
4
+
5
+ Fork of [shu0115/tap_amazing_print](https://github.com/shu0115/tap_amazing_print).
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ gem "amazing_tap", group: :development
12
+ ```
13
+
14
+ Or standalone:
15
+
16
+ ```console
17
+ gem install amazing_tap
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ require "amazing_tap"
24
+
25
+ user = { id: 7, name: "Ada" }
26
+
27
+ user.tapp
28
+ # user (Hash)
29
+ # {
30
+ # :id => 7,
31
+ # :name => "Ada"
32
+ # }
33
+
34
+ account.owner.tapp # chains inferred as written: "account.owner (Hash)"
35
+ user.tapp(:after_update) # explicit label instead of inference
36
+ user.tapp(type: false) # label without the class
37
+ user.tapp(backtrace: true) # appends " from <frame>" lines for the full caller
38
+ user.tapp(backtrace: 3) # first 3 frames only
39
+ ```
40
+
41
+ Label inference reads the receiver expression at the call site. It covers local variables, `@ivars`, `$globals`, dotted chains, and index access. When the source is not inferable (literals, parenthesized calls, multiline chains, REPL/eval), the header falls back to the class alone:
42
+
43
+ ```ruby
44
+ { a: 1 }.tapp
45
+ # (Hash)
46
+ # { :a => 1 }
47
+ ```
48
+
49
+ Long output gets a closing marker so you can tell where each dump ends:
50
+
51
+ ```ruby
52
+ big_list.tapp
53
+ # big_list (Array)
54
+ # [
55
+ # ... more than 24 lines ...
56
+ # ]
57
+ # /big_list
58
+ ```
59
+
60
+ ### Configuration
61
+
62
+ ```ruby
63
+ AmazingTap.closing_threshold = 40 # lines before the closing "/label" appears; default 24
64
+ ```
65
+
66
+ Output is colorized whenever amazing_print would colorize (tty, or `AmazingPrint.force_colors!`).
67
+
68
+ ### tapap
69
+
70
+ `tapap` is an alias of `tapp`.
71
+
72
+ ## Development
73
+
74
+ ```console
75
+ bundle install
76
+ bundle exec rspec
77
+ ```
78
+
79
+ ## License
80
+
81
+ MIT. See [LICENSE.txt](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmazingTap
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "amazing_tap/version"
4
+ require 'amazing_print'
5
+
6
+ module AmazingTap
7
+ class Error < StandardError; end
8
+
9
+ DEFAULT_CLOSING_THRESHOLD = 24
10
+
11
+ RECEIVER_PATTERN = /([\w@$.\[\]!?]+)\s*\.\s*tap(?:p|ap)\b/
12
+
13
+ class << self
14
+ # Printed output longer than this many lines gets a closing "/label" line.
15
+ #
16
+ # @return [Integer] line count threshold, DEFAULT_CLOSING_THRESHOLD unless set
17
+ attr_writer :closing_threshold
18
+
19
+ def closing_threshold
20
+ @closing_threshold ||= DEFAULT_CLOSING_THRESHOLD
21
+ end
22
+
23
+ # Extracts the receiver expression preceding .tapp/.tapap on the call-site
24
+ # line, e.g. "user" for `user.tapp` or "account.owner" for
25
+ # `account.owner.tapp`. Inference is textual: literals, parenthesized
26
+ # calls, multiline chains, or unreadable sources (eval, REPL) yield nil.
27
+ #
28
+ # @param location [Thread::Backtrace::Location] the tapp call site
29
+ # @return [String, nil] the receiver expression, or nil when not inferable
30
+ def infer_label(location)
31
+ path = location.path
32
+ return nil unless path && File.readable?(path)
33
+
34
+ line = File.readlines(path)[location.lineno - 1]
35
+ line && line[RECEIVER_PATTERN, 1]
36
+ end
37
+
38
+ # Prints a header line (label and/or class) followed by the ap-formatted
39
+ # object, then optional caller frames. Output longer than
40
+ # .closing_threshold lines is closed with a "/label" line so long dumps
41
+ # stay identifiable. Colorized under the same conditions amazing_print
42
+ # colorizes its output.
43
+ #
44
+ # @param object [Object] the object to print
45
+ # @param label [Symbol, String, nil] label for the header; nil prints a
46
+ # class-only header (or none with type: false)
47
+ # @param callers [Array<String>] backtrace of the tapp call site
48
+ # @param type [Boolean] append the object's class to the header
49
+ # @param backtrace [Boolean, Integer] print all caller frames (true) or the
50
+ # first N frames (Integer) after the object
51
+ # @return [void]
52
+ def print_labeled(object, label, callers:, type: true, backtrace: false)
53
+ colorize = AmazingPrint::Inspector.new.colorize?
54
+
55
+ header = []
56
+ header << (colorize ? AmazingPrint::Colors.yellow(label.to_s) : label.to_s) if label
57
+ if type
58
+ type_text = "(#{object.class})"
59
+ header << (colorize ? AmazingPrint::Colors.whiteish(type_text) : type_text)
60
+ end
61
+ puts header.join(" ") unless header.empty?
62
+
63
+ body = object.ai
64
+ puts body
65
+
66
+ frames = backtrace == true ? callers : callers.first(backtrace || 0)
67
+ frames.each { |frame| puts " from #{frame}" }
68
+
69
+ return unless label && body.lines.length + frames.length > closing_threshold
70
+
71
+ closing = "/#{label}"
72
+ puts colorize ? AmazingPrint::Colors.yellow(closing) : closing
73
+ end
74
+ end
75
+
76
+ module ObjectExtension
77
+ # Prints the receiver via amazing_print with a labeled header, then
78
+ # returns it, so calls chain safely. Without an explicit label, the label
79
+ # is inferred from the receiver expression at the call site; when
80
+ # inference fails the header shows only the class.
81
+ #
82
+ # @param label [Symbol, nil] explicit label; nil infers from the call site
83
+ # @param type [Boolean] append the receiver's class to the header
84
+ # @param backtrace [Boolean, Integer] print all caller frames (true) or
85
+ # the first N frames (Integer) after the output
86
+ # @return [self]
87
+ # @raise [ArgumentError] when label is neither nil nor a Symbol
88
+ def tapp(label = nil, type: true, backtrace: false)
89
+ raise ArgumentError, "label must be a Symbol" unless label.nil? || label.is_a?(Symbol)
90
+
91
+ label ||= AmazingTap.infer_label(caller_locations(1, 1).first)
92
+ AmazingTap.print_labeled(self, label, callers: caller, type: type, backtrace: backtrace)
93
+ self
94
+ end
95
+ alias tapap tapp
96
+ end
97
+ end
98
+
99
+ class Object
100
+ include AmazingTap::ObjectExtension
101
+ end
@@ -0,0 +1,4 @@
1
+ module AmazingTap
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amazing_tap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Portales Rosado
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: amazing_print
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: 'Labeled tap debugging via amazing_print: obj.tap(:label) with type,
41
+ backtrace and closing markers'
42
+ email:
43
+ - dportalesr@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/amazing_tap.rb
55
+ - lib/amazing_tap/version.rb
56
+ - sig/amazing_tap.rbs
57
+ homepage: https://github.com/dportalesr/amazing_tap
58
+ licenses:
59
+ - MIT
60
+ metadata:
61
+ allowed_push_host: https://rubygems.org
62
+ homepage_uri: https://github.com/dportalesr/amazing_tap
63
+ source_code_uri: https://github.com/dportalesr/amazing_tap
64
+ changelog_uri: https://github.com/dportalesr/amazing_tap/CHANGELOG.md
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.0.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.7.2
80
+ specification_version: 4
81
+ summary: amazing_tap
82
+ test_files: []