class Net::IMAP::Config


NOTE: Updates to config objects are not synchronized for thread-safety.
== Thread Safety
client.responses.values.all?(&:frozen?) # => true
client.responses.frozen? # => true
client.config.response_without_args # => :frozen_dup
client = Net::IMAP.new(hostname, config: :future)
For example, to disable all currently deprecated behavior:
The planned eventual config for some future x.y version.
[:future]
The planned config for the next x.y version.
[:next]
An alias for the current x.y version’s defaults.
[:current]
attributes from Config.global, for example: #debug.
NOTE: This is not the same as Config.default. It inherits some
>>>
An alias for :current.
[:default]

In addition to x.y version numbers, the following aliases are supported:
=== Named defaults
client.config.sasl_ir # => false
Net::IMAP.config.load_defaults 0.3
client.config.sasl_ir # => true
client = Net::IMAP.new(hostname)
Use #load_defaults to globally behave like a specific version:
client.config.debug? # => true
Net::IMAP.debug = true
client.config.debug? # => false
Net::IMAP.debug = false
client = Net::IMAP.new(hostname, config: 0.4)
Config.global, for example #debug:
The versioned default configs inherit certain specific config options from
client.config.responses_without_block # => :frozen_dup
client.config.sasl_ir # => true
client = Net::IMAP.new(hostname, config: :future)
client.config.responses_without_block # => :warn
client.config.sasl_ir # => true
client = Net::IMAP.new(hostname, config: 0.5)
client.config.responses_without_block # => :silence_deprecation_warning
client.config.sasl_ir # => true
client = Net::IMAP.new(hostname, config: 0.4)
client.config.responses_without_block # => :silence_deprecation_warning
client.config.sasl_ir # => false
client = Net::IMAP.new(hostname, config: 0.3)
enables extra backward compatibility with those versions:
Net::IMAP.new. Requesting default configurations for previous versions
net-imap can be loaded with the config keyword argument to
The effective default configuration for a specific x.y version of
== Versioned defaults
plain_client.config.debug? # => false
plain_client.config.inherited?(:debug) # => true
plain_client.config.reset(:debug)
plain_client.config.debug? # => true
plain_client.config.inherited?(:debug) # => false
plain_client.config.debug = true
Net::IMAP.debug = false
quiet_client.config.debug? # => false
debug_client.config.debug? # => true
plain_client.config.debug? # => true
Net::IMAP.debug = true
# Net::IMAP.debug is delegated to Net::IMAP::Config.global.debug
quiet_client.config.debug? # => false
debug_client.config.debug? # => true
plain_client.config.debug? # => false
quiet_client.config.inherited?(:debug) # => false
debug_client.config.inherited?(:debug) # => false
plain_client.config.inherited?(:debug) # => true
quiet_client = Net::IMAP.new(hostname, debug: false)
debug_client = Net::IMAP.new(hostname, debug: true)
plain_client = Net::IMAP.new(hostname)
configs inherit from Config.global.
value. Every client creates its own specific config. By default, client
any attributes which have not been set locally will inherit the parent’s
Configs have a parent config, and
== Inheritance
quiet_client.config.debug? # => false
debug_client.config.debug? # => true
quiet_client = Net::IMAP.new(hostname, debug: false)
debug_client = Net::IMAP.new(hostname, debug: true)
config.
Net::IMAP.new are delegated to Config.new. Every client has its own
When creating a new client, all unhandled keyword arguments to
client-specific configuration can be seen at Net::IMAP#config.
be seen at either Net::IMAP.config or Net::IMAP::Config.global, and the
configuration options for Net::IMAP clients. The global configuration can
Net::IMAP::Config (available since v0.4.13) stores

def self.[](config)

Given a config, returns that same config.

Config.global. Use Config.new for an unfrozen config.
Given a Hash, creates a new _frozen_ config which inherits from

version. See Config@Named+defaults.
Given a version name, returns the default configuration for the target

version. See Config@Versioned+defaults.
Given a version number, returns the default configuration for the target

Net::IMAP::Config[config] -> same config
Net::IMAP::Config[hash] -> new frozen config
Net::IMAP::Config[symbol] -> named config
Net::IMAP::Config[number] -> versioned config
:call-seq:
def self.[](config)
  if    config.is_a?(Config)         then config
  elsif config.nil? && global.nil?   then nil
  elsif config.respond_to?(:to_hash) then new(global, **config).freeze
  else
    version_defaults[config] or
      case config
      when Numeric
        raise RangeError, "unknown config version: %p" % [config]
      when String, Symbol
        raise KeyError, "unknown config name: %p" % [config]
      else
        raise TypeError, "no implicit conversion of %s to %s" % [
          config.class, Config
        ]
      end
  end
end

def self.default; @default end

The default config, which is hardcoded and frozen.
def self.default; @default end

def self.global; @global if defined?(@global) end

The global config object. Also available from Net::IMAP.config.
def self.global; @global if defined?(@global) end

def self.version_defaults; @version_defaults end

Net::IMAP::Config["0.5.6"] == Net::IMAP::Config[0.5r] # => true
Net::IMAP::Config["current"] == Net::IMAP::Config[:current] # => true
Net::IMAP::Config[0.5] == Net::IMAP::Config[0.5r] # => true
Net::IMAP::Config.version_defaults[0.5] == Net::IMAP::Config[0.5]
For example:

Config::[] gets named or numbered versions from this hash.

+to_r+/+to_f+ with a non-zero number.
Values can be accessed with any object that responds to +to_sym+ or
A hash of hard-coded configurations, indexed by version number or name.
def self.version_defaults; @version_defaults end

def defaults_hash

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

def initialize(parent = Config.global, **attrs)

If a block is given, the new config object is yielded to it.

If +parent+ is not given, the global config is used by default.

Creates a new config object and initialize its attribute with +attrs+.
def initialize(parent = Config.global, **attrs)
  super(parent)
  update(**attrs)
  yield self if block_given?
end

def load_defaults(version)

See Config@Versioned+defaults and Config@Named+defaults.

is usually Config.global) and are left unchanged, for example: #debug.
Some config attributes default to inheriting from their #parent (which

configuration for +version+. #parent will not be changed.
Resets the current config to behave like the versioned default

:call-seq: load_defaults(version) -> self
def load_defaults(version)
  [Numeric, Symbol, String].any? { _1 === version } or
    raise ArgumentError, "expected number or symbol, got %p" % [version]
  update(**Config[version].defaults_hash)
end

def to_h; data.members.to_h { [_1, send(_1)] } end

Returns all config attributes in a hash.

:call-seq: to_h -> hash
def to_h; data.members.to_h { [_1, send(_1)] } end

def update(**attrs)

invalid attribute value, +attrs+ may be partially applied.
*NOTE:* #update is not atomic. If an exception is raised due to an
>>>

assignment method on Config.
An ArgumentError is raised unless every key in +attrs+ matches an

Assigns all of the provided +attrs+ to this config, and returns +self+.

:call-seq: update(**attrs) -> self
def update(**attrs)
  unless (bad = attrs.keys.reject { respond_to?(:"#{_1}=") }).empty?
    raise ArgumentError, "invalid config options: #{bad.join(", ")}"
  end
  attrs.each do send(:"#{_1}=", _2) end
  self
end

def with(**attrs)

If +self+ is frozen, the copy will also be frozen.

If no keyword arguments are given, an ArgumentError will be raised.

block, yields the new config and returns the block's result.
Without a block, returns a new config which inherits from self. With a

with(**attrs) {|config| } -> result
with(**attrs) -> config
:call-seq:
def with(**attrs)
  attrs.empty? and
    raise ArgumentError, "expected keyword arguments, none given"
  copy = new(**attrs)
  copy.freeze if frozen?
  block_given? ? yield(copy) : copy
end