Sha256: 21ce3748ed80c2133b82a99994389e27695af863cc4d9d89ee97713ab09eb720

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "dry/configurable"
require_relative "config"

module Hanami
  module Assets
    # @since 2.0.0
    # @api public
    class AppConfig
      include Dry::Configurable

      # @since 2.0.0
      # @api private
      attr_reader :base_config
      protected :base_config

      setting :server_url, default: "http://localhost:8080"

      # @since 2.0.0
      # @api private
      def initialize(*)
        super

        @base_config = Config.new
      end

      def initialize_copy(source)
        super
        @base_config = source.base_config.dup
      end

      # @since 2.0.0
      # @api private
      def finalize!
      end

      # Returns the list of available settings
      #
      # @return [Set]
      #
      # @since 2.0.0
      # @api private
      def settings
        base_config.settings + self.class.settings
      end

      private

      # @since 2.0.0
      # @api private
      def method_missing(name, *args, &block)
        if config.respond_to?(name)
          config.public_send(name, *args, &block)
        elsif base_config.respond_to?(name)
          base_config.public_send(name, *args, &block)
        else
          super
        end
      end

      # @since 2.0.0
      # @api private
      def respond_to_missing?(name, _incude_all = false)
        config.respond_to?(name) || base_config.respond_to?(name) || super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-2.0.0.beta4 lib/hanami/assets/app_config.rb