Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ New config option to return frozen dup from #responses #334

Merged
merged 8 commits into from
Oct 13, 2024

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Oct 7, 2024

Add :frozen_dup option to Config#responses_without_block. When set to :frozen_dup, IMAP#responses called without a type or a block will return a frozen duplicate or the responses hash. The hash's array values will also be frozen dups. None of the values in those arrays will be frozen, but writing to those should be uncommon. (Net::IMAP itself will never update any response structs.)

Because responses(type) is relatively new and has always raised an exception, we can update it to always return a frozen dup array without breaking backward compatibility. This is done regardless of the config option. The config name (config.responses_without_block) is a little misleading now, but it's kept for backward compatibility. config.responses_without_args was added as an alias.

@nevans nevans added this to the v0.5 milestone Oct 7, 2024
@nevans
Copy link
Collaborator Author

nevans commented Oct 8, 2024

@shugo Any thoughts on this? I originally thought it would be better to always crash, but I can't remember why I thought that. Returning a frozen copy will still crash with some code, but it will work just fine for many others.

@shugo
Copy link
Member

shugo commented Oct 10, 2024

@shugo Any thoughts on this? I originally thought it would be better to always crash, but I can't remember why I thought that. Returning a frozen copy will still crash with some code, but it will work just fine for many others.

I agree with the proposed change. Thank you.

@nevans nevans force-pushed the responses-return-frozen_dup branch from 6411ac1 to f0e83ae Compare October 12, 2024 14:35
I tried using markdown for the tables, but it screwed up other
formatting.  This format (with definition lists) is more "standard" for
rdoc.
`test_imap.rb` is huge!

`wait_for_response_count` was moved into TestCase (in test/lib/helper).
Perhaps this should be moved into a shared module or an IMAPTestCase
class (subclass of TestCase) instead?
Two args (counting the block arg) => four tests.

Only the original (no args) form is affected by
`config.responses_without_block`, so the others make their assertions
for every possible config setting.
The same message is used for both the warning and the ArgumentError.
Because responses(type) is relatively new and has always raised an
exception, we can update it to return a frozen dup array without
breaking backward compatibility.

Additionally, `config.responses_without_args` was added as an alias for
`config.responses_without_block`.  The original name is a little
misleading now, but it's kept for backward compatibility.
This adds a new `:frozen_dup` option to `config.responses_without_block`
which allows it to return a frozen copy of the responses hash, with each
response type array also being a frozen copy.
This seems like a better API than _always_ crashing.  Now that we have a
config option for it, it should become the default in v0.6.
@nevans nevans force-pushed the responses-return-frozen_dup branch from f0e83ae to 566e668 Compare October 13, 2024 02:40
@nevans nevans merged commit 0f7d264 into master Oct 13, 2024
18 checks passed
@nevans nevans deleted the responses-return-frozen_dup branch October 13, 2024 02:47
nevans added a commit that referenced this pull request Oct 13, 2024
…-frozen_dup

✨ New config option to return frozen dup from #responses [backport: #334]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants