Sha256: 13ac33cc3ee6b3f878b76ef668dbfba20cd0f5f5dd20b7cc38e5126de25f0ad6

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require "dry/configurable/config"
require "dry/configurable/methods"

module Dry
  module Configurable
    # Initializer method which is prepended when `Dry::Configurable`
    # is included in a class
    #
    # @api private
    module Initializer
      # @api private
      def initialize(*)
        # Dup settings at time of initializing to ensure setting values are specific to
        # this instance. This does mean that any settings defined on the class _after_
        # initialization will not be available on the instance.
        @config = Config.new(self.class._settings.dup)

        super
      end
      ruby2_keywords(:initialize) if respond_to?(:ruby2_keywords, true)
    end

    # Instance-level API when `Dry::Configurable` is included in a class
    #
    # @api public
    module InstanceMethods
      include Methods

      # Return object's configuration
      #
      # @return [Config]
      #
      # @api public
      attr_reader :config

      # Finalize the config and freeze the object
      #
      # @api public
      def finalize!(freeze_values: false)
        super
        freeze
      end

      private

      # @api public
      def initialize_copy(source)
        super
        @config = source.config.dup
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-configurable-0.15.0 lib/dry/configurable/instance_methods.rb