File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,19 @@ def self.default; @default end
66
66
# The global config object. Also available from Net::IMAP.config.
67
67
def self . global ; @global end
68
68
69
- def self . []( config ) # :nodoc: unfinished API
69
+ # :call-seq:
70
+ # Net::IMAP::Config[hash] -> new frozen config
71
+ # Net::IMAP::Config[config] -> same config
72
+ #
73
+ # Given a Hash, creates a new _frozen_ config which inherits from
74
+ # Config.global. Use Config.new for an unfrozen config.
75
+ #
76
+ # Given a config, returns that same config.
77
+ def self . []( config )
70
78
if config . is_a? ( Config ) || config . nil? && global . nil?
71
79
config
80
+ elsif config . respond_to? ( :to_hash )
81
+ new ( global , **config ) . freeze
72
82
else
73
83
raise TypeError , "no implicit conversion of %s to %s" % [
74
84
config . class , Config
Original file line number Diff line number Diff line change @@ -135,10 +135,22 @@ class ConfigTest < Test::Unit::TestCase
135
135
assert_equal false , child . debug?
136
136
end
137
137
138
+ test ".[] with a hash" do
139
+ config = Config [ { responses_without_block : :raise , sasl_ir : false } ]
140
+ assert config . frozen?
141
+ refute config . sasl_ir?
142
+ assert config . inherited? ( :debug )
143
+ refute config . inherited? ( :sasl_ir )
144
+ assert_same Config . global , config . parent
145
+ assert_same :raise , config . responses_without_block
146
+ end
147
+
138
148
test ".new always sets a parent" do
139
149
assert_same Config . global , Config . new . parent
140
150
assert_same Config . default , Config . new ( Config . default ) . parent
141
151
assert_same Config . global , Config . new ( Config . global ) . parent
152
+ assert_equal true , Config . new ( { debug : true } , debug : false ) . parent . debug?
153
+ assert_equal true , Config . new ( { debug : true } , debug : false ) . parent . frozen?
142
154
end
143
155
144
156
test "#freeze" do
You can’t perform that action at this time.
0 commit comments