Eagerly open file for appending in OrderReporter#358
Closed
Conversation
30544ba to
e37158d
Compare
davidstosik
approved these changes
Aug 25, 2025
Contributor
There was a problem hiding this comment.
I have the uneasy feeling that opening the file too early might cause other issues, but I can't pinpoint a proper reason.
This might just be fine as-is. 👍🏻
Oh here's one: are there scenarios in which OrderReporter would be initialized (meaning it will open the file), but #report wont be called (meaning it wouldn't close it)?
Comment on lines
26
to
27
| attr_reader :file | ||
| private :file |
Contributor
There was a problem hiding this comment.
That works, but I feel like we rarely see it written that way.
Why not this? 👇🏻
Suggested change
| attr_reader :file | |
| private :file | |
| private | |
| attr_reader :file |
| def initialize(options = {}) | ||
| @path = options.delete(:path) | ||
| @file = nil | ||
| @file ||= File.open(@path, 'a+') |
Contributor
There was a problem hiding this comment.
Since we're initializing, there's no scenario in which @file is already set at this point?
Suggested change
| @file ||= File.open(@path, 'a+') | |
| @file = File.open(@path, 'a+') |
Member
Author
There was a problem hiding this comment.
Yep got that one thanks
e37158d to
8daad48
Compare
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.
No description provided.