Customizable key-value separator and quoting to be machine-readable#130
Customizable key-value separator and quoting to be machine-readable#130modulitos wants to merge 4 commits intobasecamp:masterfrom
Conversation
|
@sj26 I would love to get a review on this PR when you have a chance. Or let me know if there's anything I can do to help get this reviewed. |
|
Kindly pinging the marginalia authors (@arthurnn @jeremy) - is there anything I can do to help get this PR reviewed? Also pinging @balachandr and @odeke-em, as you both had comments in the original PR: #89 I did my best to write up a concise description of the new behavior, and demonstrate that it's all backwards compatible. |
jeremy
left a comment
There was a problem hiding this comment.
Would approach this as configuring a formatter rather than as configuring the low-level details of key/value output.
lib/marginalia.rb
Outdated
| ensure | ||
| prev.each { |(key, value)| Marginalia::Comment.send(:"#{key}=", value) } | ||
| end | ||
|
|
There was a problem hiding this comment.
Appears to be a test helper. Would move this to a utility method on the test case rather than introduce new toplevel API.
There was a problem hiding this comment.
Thanks for catching this 💯
I ended up removing this test helper, since it introduces indirection that doesn't seem worthwhile.
lib/marginalia/comment.rb
Outdated
| if component_value.present? | ||
| ret << "#{c}:#{component_value}," | ||
| ret << "#{c}#{key_value_separator}"\ | ||
| "#{quote_value(component_value)}," |
There was a problem hiding this comment.
Suggest introducing a configurable formatter block rather than separate low-level config points, including :default and :sqlcommenter shorthands for "standard" formatters.
There was a problem hiding this comment.
Done 👍
I added support for configuring "standard" formatters like :sqlcommenter directly via Marginalia::Comment.update_formatter!(:sqlcommenter), and I removed configuration for key_value_separator and quote_value directly on the Comment module since it seemed like YAGNI.
I agree that those low-level config points should be managed together, so I introduced a FormatterFactory that handles the composition of these configs instead. I think this results in a better separation of concerns between the formatting and commenting logic as well. Open to feedback, of course :)
modulitos
left a comment
There was a problem hiding this comment.
Thanks @jeremy - I appreciate the great feedback!
Your suggestions led me to think deeper on the formatting logic, resulting in improvements to the API and code organization. Looking forward to your thoughts on the latest changes.
lib/marginalia.rb
Outdated
| ensure | ||
| prev.each { |(key, value)| Marginalia::Comment.send(:"#{key}=", value) } | ||
| end | ||
|
|
There was a problem hiding this comment.
Thanks for catching this 💯
I ended up removing this test helper, since it introduces indirection that doesn't seem worthwhile.
lib/marginalia/comment.rb
Outdated
| if component_value.present? | ||
| ret << "#{c}:#{component_value}," | ||
| ret << "#{c}#{key_value_separator}"\ | ||
| "#{quote_value(component_value)}," |
There was a problem hiding this comment.
Done 👍
I added support for configuring "standard" formatters like :sqlcommenter directly via Marginalia::Comment.update_formatter!(:sqlcommenter), and I removed configuration for key_value_separator and quote_value directly on the Comment module since it seemed like YAGNI.
I agree that those low-level config points should be managed together, so I introduced a FormatterFactory that handles the composition of these configs instead. I think this results in a better separation of concerns between the formatting and commenting logic as well. Open to feedback, of course :)
| desc "test sqlite3 driver" | ||
| task :sqlite do | ||
| sh "DRIVER=sqlite3 bundle exec ruby -Ilib -Itest test/*_test.rb" | ||
| sh "DRIVER=sqlite3 bundle exec ruby -Ilib -Itest test/query_comments_test.rb" |
There was a problem hiding this comment.
I changed these globs from test/*_test.rb to test/query_comments_test.rb since that's the only file that needs to be matched for the database tests. It also allows us to run the formatting tests separately.
This pull request surfaces a new optional configuration to format the Marginalia comments in a machine-readable manner. See the changes to the README in this PR for a summary of the new feature.
Note that this PR is backwards-compatible with existing code. The new setting is optional, and if unset, the default values will retain all existing behavior. Unit tests have also be added to ensure there are no regressions.
Further notes:
TODO:
Note that some changes were made to the API of this feature over the course of this PR. Here is the original description, for posterity: