Add PrecompiledAssets::Manifest#inspect#1
Open
NiklasHae wants to merge 1 commit intomakandra:mainfrom
Open
Conversation
Instead of relying on the #inpect default implementation it truncates @parsed_manifest (a potenitally huge hash filling many terminal windows with characters)
foobear
reviewed
Jul 26, 2023
Comment on lines
+33
to
+34
| truncated_parsed_manifest = "#{@parsed_manifest.to_s[0..7]}..." | ||
| "<#{self.class.name}:#{object_id} @pathname=#{@pathname.inspect} @parsed_manifest=#{truncated_parsed_manifest}>" |
Member
There was a problem hiding this comment.
Thanks for your suggestion. A useful inspection does make sense.
However, I think there is room for improvement here.
- Convention for object inspection is to start with
#<, not<#. - If the manifest has not yet been parsed this inspects with
@parsed_manifest=...instead of@pared_manifest=.... - I'm not sure how helpful the first 8 characters of the manifest.json can be. Maybe we should show more characters, or offer some kind of aggregation, like
@parsed_manifest=(23 entries). - The
object_idis not actually put directly into inspection by default, but implementation varies across Ruby versions, so maybe don't want to go there. I'm fine with keeping it as implemented, or not displaying it at all.
With a few adjustments, we can get an inspection like
#<PrecompiledAssets::Manifest:12345 @pathname=#<Pathname:/path/to/manifest.json> @parsed_manifest={"application.js"=>"application-5ZACKM24...>
or, if the manifest has not been parsed,
#<PrecompiledAssets::Manifest:12345 @pathname=#<Pathname:/path/to/manifest.json> @parsed_manifest=nil>
Suggested change
| truncated_parsed_manifest = "#{@parsed_manifest.to_s[0..7]}..." | |
| "<#{self.class.name}:#{object_id} @pathname=#{@pathname.inspect} @parsed_manifest=#{truncated_parsed_manifest}>" | |
| manifest_inspection = @parsed_manifest.inspect.sub(/\A(.{40}).+\z/, '\1...') | |
| "#<{self.class.name}:#{object_id} @pathname=#{@pathname.inspect} @parsed_manifest=#{manifest_inspection}>" |
Member
Author
There was a problem hiding this comment.
- Good catch
- 👍
- I like the
@parsed_manifest=(23 entries)suggestion 👍 - I've been here https://bugs.ruby-lang.org/issues/17199 before, and I just used object_id :D. A little bit weird for Ruby to not have a straightforward way to override #inspect.
Since I'm running a patched version anyways, I'll look into adapting this PR with your suggestions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sometimes an exception leads to printing the inspected manifest object. This fills multiple screens with the parsed manifest hash. Most of the times though, the exception's message
Could not find "foobar.css" in manifest: <PrecompiledAssets::Manifest ....>already helps to solve the problem.Instead of relying on the #inpect default implementation it truncates @parsed_manifest.
Feel free to decline without comment if you don't want this change merged ;) Thx 👍