模块 Net::IMAP::Config::AttrInheritance
注意: 此模块上的公共方法是
Net::IMAP::Config稳定公共 API 的一部分。但模块本身是一个内部实现细节,不保证向后兼容性。
当本地值不包含覆盖时,attr_accessor 方法将委托给它们的 parent。继承形成一个单链表,因此查找将在祖先数量上为 O(n)。实际上,祖先链预计不会很长。在没有自定义的情况下,它只有三层深
当使用 config 关键字创建客户端时,例如,为了在仍然依赖全局配置 debug 或 logger 的同时使用应用程序或库的适当默认值,祖先链很可能仍然只有四层深
IMAP#config→ 备用默认值 →Config.global→Config.default
常量
- INHERITED
属性
parent[R]
父 Config 对象
私有类方法
included(mod) 点击切换源代码
# File net-imap-0.5.4/lib/net/imap/config/attr_inheritance.rb, line 34 def self.included(mod) mod.extend Macros end
公共实例方法
inherited?(attr) 点击切换源代码
如果 attr 是从 parent 继承的,并且没有被此配置覆盖,则返回 true。
# File net-imap-0.5.4/lib/net/imap/config/attr_inheritance.rb, line 59 def inherited?(attr) data[attr] == INHERITED end
new(**attrs) 点击切换源代码
创建一个新的配置,它继承自 self。
# File net-imap-0.5.4/lib/net/imap/config/attr_inheritance.rb, line 55 def new(**attrs) self.class.new(self, **attrs) end
reset → self 点击切换源代码
reset(attr) → 属性值
重置 attr 以从 parent 配置继承。
当 attr 为 nil 或未给定,则重置所有属性。
# File net-imap-0.5.4/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
受保护的实例方法
initialize(parent = nil) 点击切换源代码
调用超类方法
# File net-imap-0.5.4/lib/net/imap/config/attr_inheritance.rb, line 48 def initialize(parent = nil) # :notnew: super() @parent = Config[parent] reset end
私有实例方法
initialize_copy(other) 点击切换源代码
调用超类方法
# File net-imap-0.5.4/lib/net/imap/config/attr_inheritance.rb, line 82 def initialize_copy(other) super @parent ||= other # only default has nil parent end