Skip to content

Commit 198c3e6

Browse files
committed
🔧 Add a default config object
1 parent d63022f commit 198c3e6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/net/imap/config.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,35 @@ class IMAP
1313
# *NOTE:* Updates to config objects are not synchronized for thread-safety.
1414
#
1515
class Config
16+
# The default config, which is hardcoded and frozen.
17+
def self.default; @default end
18+
1619
include AttrAccessors
1720

1821
# The debug mode (boolean)
22+
#
23+
# | Starting with version | The default value is |
24+
# |-----------------------|----------------------|
25+
# | _original_ | +false+ |
1926
attr_accessor :debug
2027
alias debug? debug
2128

2229
# Seconds to wait until a connection is opened.
2330
#
2431
# If the IMAP object cannot open a connection within this time,
2532
# it raises a Net::OpenTimeout exception. See Net::IMAP.new.
33+
#
34+
# | Starting with version | The default value is |
35+
# |-----------------------|----------------------|
36+
# | _original_ | +30+ seconds |
2637
attr_accessor :open_timeout
2738

2839
# Seconds to wait until an IDLE response is received, after
2940
# the client asks to leave the IDLE state. See Net::IMAP#idle_done.
41+
#
42+
# | Starting with version | The default value is |
43+
# |-----------------------|----------------------|
44+
# | _original_ | +5+ seconds |
3045
attr_accessor :idle_response_timeout
3146

3247
# Creates a new config object and initialize its attribute with +attrs+.
@@ -38,6 +53,12 @@ def initialize(**attrs)
3853
yield self if block_given?
3954
end
4055

56+
@default = new(
57+
debug: false,
58+
open_timeout: 30,
59+
idle_response_timeout: 5,
60+
).freeze
61+
4162
end
4263
end
4364
end

test/net/imap/test_config.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ class ConfigTest < Test::Unit::TestCase
2424
refute config.debug?
2525
end
2626

27+
test ".default" do
28+
default = Config.default
29+
assert default.equal?(Config.default)
30+
assert default.is_a?(Config)
31+
assert default.frozen?
32+
refute default.debug?
33+
end
34+
2735
end

0 commit comments

Comments
 (0)