Sha256: 371e5e36e8afa4459a07495894c0bfb1c1926cb484e7535afd21b7a24e4ae807

Contents?: true

Size: 1.82 KB

Versions: 17

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require "forwardable"

module Net
  class IMAP
    class Config
      # >>>
      #   *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.
      module AttrAccessors
        module Macros # :nodoc: internal API
          def attr_accessor(name) AttrAccessors.attr_accessor(name) end
        end
        private_constant :Macros

        def self.included(mod)
          mod.extend Macros
        end
        private_class_method :included

        extend Forwardable

        def self.attr_accessor(name) # :nodoc: internal API
          name = name.to_sym
          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

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

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

        # Freezes the internal attributes struct, in addition to +self+.
        def freeze
          data.freeze
          super
        end

        protected

        attr_reader :data # :nodoc: internal API

        private

        def initialize_clone(other)
          super
          @data = other.data.clone
        end

        def initialize_dup(other)
          super
          @data = other.data.dup
        end

      end
    end
  end
end

Version data entries

17 entries across 16 versions & 4 rubygems

Version Path
net-imap-0.5.6 lib/net/imap/config/attr_accessors.rb
net-imap-0.4.19 lib/net/imap/config/attr_accessors.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/net-imap-0.5.1/lib/net/imap/config/attr_accessors.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/net-imap-0.5.1/lib/net/imap/config/attr_accessors.rb
net-imap-0.5.5 lib/net/imap/config/attr_accessors.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/net-imap-0.4.14/lib/net/imap/config/attr_accessors.rb
net-imap-0.5.4 lib/net/imap/config/attr_accessors.rb
net-imap-0.5.3 lib/net/imap/config/attr_accessors.rb
net-imap-0.5.2 lib/net/imap/config/attr_accessors.rb
net-imap-0.4.18 lib/net/imap/config/attr_accessors.rb
net-imap-0.5.1 lib/net/imap/config/attr_accessors.rb
net-imap-0.5.0 lib/net/imap/config/attr_accessors.rb
net-imap-0.4.17 lib/net/imap/config/attr_accessors.rb
net-imap-0.4.16 lib/net/imap/config/attr_accessors.rb
net-imap-0.4.15 lib/net/imap/config/attr_accessors.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/net-imap-0.4.14/lib/net/imap/config/attr_accessors.rb
net-imap-0.4.14 lib/net/imap/config/attr_accessors.rb