-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
@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. |
6411ac1
to
f0e83ae
Compare
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.
f0e83ae
to
566e668
Compare
…-frozen_dup ✨ New config option to return frozen dup from #responses [backport: #334]
Add
:frozen_dup
option toConfig#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.