Skip to content

Commit 0c44378

Browse files
committed
📚 Improve rdoc for IMAP#responses
1 parent f676fb3 commit 0c44378

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

lib/net/imap.rb

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,37 +2494,78 @@ def idle_done
24942494
# responses {|hash| ...} -> block result
24952495
# responses(type) {|array| ...} -> block result
24962496
#
2497-
# Yields unhandled responses and returns the result of the block.
2498-
#
2497+
# Yields unhandled server responses and returns the result of the block.
24992498
# Unhandled responses are stored in a hash, with arrays of
25002499
# <em>non-+nil+</em> UntaggedResponse#data keyed by UntaggedResponse#name
2501-
# and ResponseCode#data keyed by ResponseCode#name. Call without +type+ to
2502-
# yield the entire responses hash. Call with +type+ to yield only the array
2503-
# of responses for that type.
2500+
# and ResponseCode#data keyed by ResponseCode#name.
2501+
#
2502+
# [With +type+]
2503+
# Yield only the array of responses for that +type+.
2504+
# When no block is given, an +ArgumentError+ is raised.
2505+
# [Without +type+]
2506+
# Yield or return the entire responses hash.
2507+
#
2508+
# When no block is given, the behavior is determined by
2509+
# Config#responses_without_block:
2510+
# >>>
2511+
# [+:silence_deprecation_warning+ <em>(original behavior)</em>]
2512+
# Returns the mutable responses hash (without any warnings).
2513+
# <em>This is not thread-safe.</em>
2514+
#
2515+
# [+:warn+ <em>(default since +v0.5+)</em>]
2516+
# Prints a warning and returns the mutable responses hash.
2517+
# <em>This is not thread-safe.</em>
2518+
#
2519+
# [+:raise+ <em>(planned future default)</em>]
2520+
# Raise an +ArgumentError+ with the deprecation warning.
25042521
#
25052522
# For example:
25062523
#
25072524
# imap.select("inbox")
25082525
# p imap.responses("EXISTS", &:last)
25092526
# #=> 2
2527+
# p imap.responses("UIDNEXT", &:last)
2528+
# #=> 123456
25102529
# p imap.responses("UIDVALIDITY", &:last)
25112530
# #=> 968263756
2531+
# p imap.responses {|responses|
2532+
# {
2533+
# exists: responses.delete("EXISTS").last,
2534+
# uidnext: responses.delete("UIDNEXT").last,
2535+
# uidvalidity: responses.delete("UIDVALIDITY").last,
2536+
# }
2537+
# }
2538+
# #=> {:exists=>2, :uidnext=>123456, :uidvalidity=>968263756}
2539+
# # "EXISTS", "UIDNEXT", and "UIDVALIDITY" have been removed:
2540+
# p imap.responses(&:keys)
2541+
# #=> ["FLAGS", "OK", "PERMANENTFLAGS", "RECENT", "HIGHESTMODSEQ"]
25122542
#
2543+
# Related: #extract_responses, #clear_responses, #response_handlers, #greeting
2544+
#
2545+
# ===== Thread safety
25132546
# >>>
25142547
# *Note:* Access to the responses hash is synchronized for thread-safety.
25152548
# The receiver thread and response_handlers cannot process new responses
25162549
# until the block completes. Accessing either the response hash or its
2517-
# response type arrays outside of the block is unsafe.
2550+
# response type arrays outside of the block is unsafe. They can be safely
2551+
# updated inside the block. Consider using #clear_responses or
2552+
# #extract_responses instead.
2553+
#
2554+
# Net::IMAP will add and remove responses from the responses hash and its
2555+
# array values, in the calling threads for commands and in the receiver
2556+
# thread, but will not modify any responses after adding them to the
2557+
# responses hash.
25182558
#
2519-
# Calling without a block is unsafe and deprecated. Future releases will
2520-
# raise ArgumentError unless a block is given.
2521-
# See Config#responses_without_block.
2559+
# ===== Clearing responses
25222560
#
25232561
# Previously unhandled responses are automatically cleared before entering a
25242562
# mailbox with #select or #examine. Long-lived connections can receive many
25252563
# unhandled server responses, which must be pruned or they will continually
25262564
# consume more memory. Update or clear the responses hash or arrays inside
2527-
# the block, or use #clear_responses.
2565+
# the block, or remove responses with #extract_responses, #clear_responses,
2566+
# or #add_response_handler.
2567+
#
2568+
# ===== Missing responses
25282569
#
25292570
# Only non-+nil+ data is stored. Many important response codes have no data
25302571
# of their own, but are used as "tags" on the ResponseText object they are
@@ -2535,8 +2576,6 @@ def idle_done
25352576
# ResponseCode#data on tagged responses. Although some command methods do
25362577
# return the TaggedResponse directly, #add_response_handler must be used to
25372578
# handle all response codes.
2538-
#
2539-
# Related: #extract_responses, #clear_responses, #response_handlers, #greeting
25402579
def responses(type = nil)
25412580
if block_given?
25422581
synchronize { yield(type ? @responses[type.to_s.upcase] : @responses) }

0 commit comments

Comments
 (0)