@@ -73,6 +73,10 @@ class IMAP
73
73
# client.config.sasl_ir # => true
74
74
# client.config.responses_without_block # => :warn
75
75
#
76
+ # client = Net::IMAP.new(hostname, config: :future)
77
+ # client.config.sasl_ir # => true
78
+ # client.config.responses_without_block # => :raise
79
+ #
76
80
# The versioned default configs inherit certain specific config options from
77
81
# Config.global, for example #debug:
78
82
#
@@ -83,6 +87,26 @@ class IMAP
83
87
# Net::IMAP.debug = true
84
88
# client.config.debug? # => true
85
89
#
90
+ # === Named defaults
91
+ # In addition to +x.y+ version numbers, the following aliases are supported:
92
+ #
93
+ # [+:default+]
94
+ # An alias for +:current+.
95
+ #
96
+ # >>>
97
+ # *NOTE*: This is _not_ the same as Config.default. It inherits some
98
+ # attributes from Config.global, for example: #debug.
99
+ # [+:current+]
100
+ # An alias for the current +x.y+ version's defaults.
101
+ # [+:next+]
102
+ # The _planned_ config for the next +x.y+ version.
103
+ # [+:future+]
104
+ # The _planned_ eventual config for some future +x.y+ version.
105
+ #
106
+ # For example, to raise exceptions for all current deprecations:
107
+ # client = Net::IMAP.new(hostname, config: :future)
108
+ # client.responses # raises an ArgumentError
109
+ #
86
110
# == Thread Safety
87
111
#
88
112
# *NOTE:* Updates to config objects are not synchronized for thread-safety.
@@ -128,6 +152,8 @@ def self.[](config)
128
152
case config
129
153
when Numeric
130
154
raise RangeError , "unknown config version: %p" % [ config ]
155
+ when Symbol
156
+ raise KeyError , "unknown config name: %p" % [ config ]
131
157
else
132
158
raise TypeError , "no implicit conversion of %s to %s" % [
133
159
config . class , Config
@@ -275,6 +301,14 @@ def to_h; data.members.to_h { [_1, send(_1)] } end
275
301
responses_without_block : :warn ,
276
302
) . freeze
277
303
304
+ version_defaults [ :default ] = Config [ 0.4 ]
305
+ version_defaults [ :current ] = Config [ 0.4 ]
306
+ version_defaults [ :next ] = Config [ 0.5 ]
307
+
308
+ version_defaults [ :future ] = Config [ 0.5 ] . dup . update (
309
+ responses_without_block : :raise ,
310
+ ) . freeze
311
+
278
312
version_defaults . freeze
279
313
end
280
314
end
0 commit comments