Skip to content

Commit

Permalink
♻️ Refactor config attrs that inherit by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Jun 22, 2024
1 parent d8ce1cb commit 4aa0f5f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,20 @@ def with(**attrs)
def load_defaults(version)
[Numeric, Symbol, String].any? { _1 === version } or
raise ArgumentError, "expected number or symbol, got %p" % [version]
config = Config[version]
defaults = config.to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
update(**defaults)
update(**Config[version].defaults_hash)
end

# :call-seq: to_h -> hash
#
# Returns all config attributes in a hash.
def to_h; data.members.to_h { [_1, send(_1)] } end

protected

def defaults_hash
to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
end

@default = new(
debug: false,
open_timeout: 30,
Expand All @@ -308,9 +312,7 @@ def to_h; data.members.to_h { [_1, send(_1)] } end

@global = default.new

version_defaults[0.4] = Config[
default.to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
]
version_defaults[0.4] = Config[default.send(:defaults_hash)]

version_defaults[0] = Config[0.4].dup.update(
sasl_ir: false,
Expand Down

0 comments on commit 4aa0f5f

Please sign in to comment.