HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/ruby-2.5.9/gems/activestorage-6.1.4.1/lib/active_storage/service/registry.rb
# frozen_string_literal: true

module ActiveStorage
  class Service::Registry #:nodoc:
    def initialize(configurations)
      @configurations = configurations.deep_symbolize_keys
      @services = {}
    end

    def fetch(name)
      services.fetch(name.to_sym) do |key|
        if configurations.include?(key)
          services[key] = configurator.build(key)
        else
          if block_given?
            yield key
          else
            raise KeyError, "Missing configuration for the #{key} Active Storage service. " \
              "Configurations available for the #{configurations.keys.to_sentence} services."
          end
        end
      end
    end

    private
      attr_reader :configurations, :services

      def configurator
        @configurator ||= ActiveStorage::Service::Configurator.new(configurations)
      end
  end
end