Sha256: b585029d38120fb8d71d69daf72390076528a2b88f619cf8c653c707dea6403a

Contents?: true

Size: 1 KB

Versions: 39

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module ActiveStorage
  class Service::Configurator #:nodoc:
    attr_reader :configurations

    def self.build(service_name, configurations)
      new(configurations).build(service_name)
    end

    def initialize(configurations)
      @configurations = configurations.deep_symbolize_keys
    end

    def build(service_name)
      config = config_for(service_name.to_sym)
      resolve(config.fetch(:service)).build(**config, configurator: self)
    end

    private
      def config_for(name)
        configurations.fetch name do
          raise "Missing configuration for the #{name.inspect} Active Storage service. Configurations available for #{configurations.keys.inspect}"
        end
      end

      def resolve(class_name)
        require "active_storage/service/#{class_name.to_s.underscore}_service"
        ActiveStorage::Service.const_get(:"#{class_name.camelize}Service")
      rescue LoadError
        raise "Missing service adapter for #{class_name.inspect}"
      end
  end
end

Version data entries

39 entries across 39 versions & 4 rubygems

Version Path
activestorage-6.0.6.1 lib/active_storage/service/configurator.rb
activestorage-6.0.6 lib/active_storage/service/configurator.rb
activestorage-6.0.5.1 lib/active_storage/service/configurator.rb
activestorage-6.0.5 lib/active_storage/service/configurator.rb
activestorage-6.0.4.8 lib/active_storage/service/configurator.rb
activestorage-6.0.4.7 lib/active_storage/service/configurator.rb
activestorage-6.0.4.6 lib/active_storage/service/configurator.rb
activestorage-6.0.4.5 lib/active_storage/service/configurator.rb
activestorage-6.0.4.4 lib/active_storage/service/configurator.rb
activestorage-6.0.4.3 lib/active_storage/service/configurator.rb
activestorage-6.0.4.2 lib/active_storage/service/configurator.rb
activestorage-6.0.4.1 lib/active_storage/service/configurator.rb
activestorage-6.0.4 lib/active_storage/service/configurator.rb
activestorage-6.0.3.7 lib/active_storage/service/configurator.rb
activestorage-6.0.3.6 lib/active_storage/service/configurator.rb
activestorage-6.0.3.5 lib/active_storage/service/configurator.rb
activestorage-6.0.3.4 lib/active_storage/service/configurator.rb
activestorage-6.0.3.3 lib/active_storage/service/configurator.rb
activestorage-6.0.3.2 lib/active_storage/service/configurator.rb
activestorage-6.0.3.1 lib/active_storage/service/configurator.rb