module Net::IMAP::Config::AttrInheritance

NOTE: The public methods on this module are part of the stable public API of Net::IMAP::Config. But the module itself is an internal implementation detail, with no guarantee of backward compatibility.

attr_accessor methods will delegate to their parent when the local value does not contain an override. Inheritance forms a singly linked list, so lookup will be O(n) on the number of ancestors. In practice, the ancestor chain is not expected to be long. Without customization, it is only three deep:

IMAP#configConfig.globalConfig.default

When creating a client with the config keyword, for example to use the appropriate defaults for an application or a library while still relying on global for configuration of debug or logger, most likely the ancestor chain is still only four deep:

IMAP#config → alternate defaults → Config.globalConfig.default

Constants

INHERITED

Attributes

parent[R]

The parent Config object

Private Class Methods

included(mod) click to toggle source
# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 34
def self.included(mod)
  mod.extend Macros
end

Public Instance Methods

inherited?(attr) click to toggle source

Returns true if attr is inherited from parent and not overridden by this config.

# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 59
def inherited?(attr) data[attr] == INHERITED end
new(**attrs) click to toggle source

Creates a new config, which inherits from self.

# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 55
def new(**attrs) self.class.new(self, **attrs) end
reset → self click to toggle source
reset(attr) → attribute value

Resets an attr to inherit from the parent config.

When attr is nil or not given, all attributes are reset.

# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 68
def reset(attr = nil)
  if attr.nil?
    data.members.each do |attr| data[attr] = INHERITED end
    self
  elsif inherited?(attr)
    nil
  else
    old, data[attr] = data[attr], INHERITED
    old
  end
end

Protected Instance Methods

initialize(parent = nil) click to toggle source
Calls superclass method
# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 48
def initialize(parent = nil) # :notnew:
  super()
  @parent = Config[parent]
  reset
end

Private Instance Methods

initialize_copy(other) click to toggle source
Calls superclass method
# File net-imap-0.4.16/lib/net/imap/config/attr_inheritance.rb, line 82
def initialize_copy(other)
  super
  @parent ||= other # only default has nil parent
end