Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ def defaults_hash
to_h.reject {|k,v| DEFAULT_TO_INHERIT.include?(k) }
end

Struct = AttrAccessors.struct
@default = AttrVersionDefaults.compile_default!
@global = default.new
AttrVersionDefaults.compile_version_defaults!
Expand Down
17 changes: 8 additions & 9 deletions lib/net/imap/config/attr_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ def self.included(mod)

def self.attr_accessor(name) # :nodoc: internal API
name = name.to_sym
raise ArgumentError, "already defined #{name}" if attributes.include?(name)
attributes << name
def_delegators :data, name, :"#{name}="
end

def self.attributes
instance_methods.grep(/=\z/).map { _1.to_s.delete_suffix("=").to_sym }
end
private_class_method :attributes
# An array of Config attribute names
singleton_class.attr_reader :attributes
@attributes = []

def self.struct # :nodoc: internal API
unless defined?(self::Struct)
const_set :Struct, Struct.new(*attributes)
end
self::Struct
attributes.freeze
Struct.new(*attributes)
end

def initialize # :notnew:
super()
@data = AttrAccessors.struct.new
@data = Config::Struct.new
end

# Freezes the internal attributes struct, in addition to +self+.
Expand Down
2 changes: 1 addition & 1 deletion test/net/imap/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def duck.to_r = 1/11111
expected = {
debug: false, open_timeout: 30, idle_response_timeout: 5, sasl_ir: true,
}
attributes = Config::AttrAccessors::Struct.members
attributes = Config::Struct.members
default_hash = Config.default.to_h
assert_equal expected, default_hash.slice(*expected.keys)
assert_equal attributes, default_hash.keys
Expand Down