Module: Net::IMAP::Config::AttrAccessors

Extended by:
Forwardable
Included in:
Net::IMAP::Config
Defined in:
lib/net/imap/config/attr_accessors.rb

Overview

NOTE: This module is an internal implementation detail, with no guarantee of backward compatibility.

attr_accessor values are stored in a struct rather than ivars, making it simpler to ensure that all config objects share a single object shape. This also simplifies iteration over all defined attributes.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

An array of Config attribute names



36
37
38
# File 'lib/net/imap/config/attr_accessors.rb', line 36

def attributes
  @attributes
end

Class Method Details

.attr_accessor(name) ⇒ Object

:nodoc: internal API

Raises:

  • (ArgumentError)


28
29
30
31
32
33
# File 'lib/net/imap/config/attr_accessors.rb', line 28

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

.structObject

:nodoc: internal API



39
40
41
42
# File 'lib/net/imap/config/attr_accessors.rb', line 39

def self.struct # :nodoc: internal API
  attributes.freeze
  Struct.new(*attributes)
end

Instance Method Details

#freezeObject

Freezes the internal attributes struct, in addition to self.



50
51
52
53
# File 'lib/net/imap/config/attr_accessors.rb', line 50

def freeze
  data.freeze
  super
end

#initializeObject

:notnew:



44
45
46
47
# File 'lib/net/imap/config/attr_accessors.rb', line 44

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