vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/lib/faraday/middleware_registry.rb
def load_middleware(key)
      value = fetch_middleware(key)
      case value
      when Module
        value
      when Symbol, String
        middleware_mutex do
          @registered_middleware[key] = const_get(value)
        end
      when Proc
        middleware_mutex do
          @registered_middleware[key] = value.call
        end
      when Array
        middleware_mutex do
          const, path = value
          if (root = @middleware_autoload_path)
            path = "#{root}/#{path}"
          end
          require(path)
          @registered_middleware[key] = const
        end
        load_middleware(key)
      end
    end
# Register middleware class(es) on the current module.
#
# @param autoload_path [String] Middleware autoload path
# @param mapping [Hash{
#          Symbol => Module,
#          Symbol => Array<Module, Symbol, String>,
#        }] Middleware mapping from a lookup symbol to a reference to the
#        middleware.
#        Classes can be expressed as:
#          - a fully qualified constant
#          - a Symbol
#          - a Proc that will be lazily called to return the former
#          - an array is given, its first element is the constant or symbol,
#            and its second is a file to `require`.
# @return [void]
#
# @example Lookup by a constant
#
#   module Faraday
#     class Whatever
#       # Middleware looked up by :foo returns Faraday::Whatever::Foo.
#       register_middleware foo: Foo
#     end
#   end
#
# @example Lookup by a symbol
#
#   module Faraday
#     class Whatever
#       # Middleware looked up by :bar returns
#       # Faraday::Whatever.const_get(:Bar)
#       register_middleware bar: :Bar
#     end
#   end
#
# @example Lookup by a symbol and string in an array
#
#   module Faraday
#     class Whatever
#       # Middleware looked up by :baz requires 'baz' and returns
#       # Faraday::Whatever.const_get(:Baz)
#       register_middleware baz: [:Baz, 'baz']
#     end
#   end
#
Register middleware class(es) on the current module.
Register middleware class ( es ) on the current module .
def load_middleware(key)
      value = fetch_middleware(key)
      case value
      when Module
        value
      when Symbol, String
        middleware_mutex do
          @registered_middleware[key] = const_get(value)
        end
      when Proc
        middleware_mutex do
          @registered_middleware[key] = value.call
        end
      when Array
        middleware_mutex do
          const, path = value
          if (root = @middleware_autoload_path)
            path = "#{root}/#{path}"
          end
          require(path)
          @registered_middleware[key] = const
        end
        load_middleware(key)
      end
    end
def load_middleware ( key ) value = fetch_middleware ( key ) case value when Module value when Symbol , String middleware_mutex do @registered_middleware [ key ] = const_get ( value ) end when Proc middleware_mutex do @registered_middleware [ key ] = value . call end when Array middleware_mutex do const , path = value if ( root = @middleware_autoload_path ) path = "#{root}/#{path}" end require ( path ) @registered_middleware [ key ] = const end load_middleware ( key ) end end
Register middleware class(es) on the current module.
Register middleware class ( es ) on the current module .
None
void
key
autoload_path
Middleware autoload path
Middleware autoload path
mapping
Middleware mapping from a lookup symbol to a reference to the middleware. Classes can be expressed as: - a fully qualified constant - a Symbol - a Proc that will be lazily called to return the former - an array is given, its first element is the constant or symbol, and its second is a file to `require`.
Middleware mapping from a lookup symbol to a reference to the middleware . Classes can be expressed as : - a fully qualified constant - a Symbol - a Proc that will be lazily called to return the former - an array is given its first element is the constant or symbol and its second is a file to ` require ` .
example
Lookup by a constant module Faraday class Whatever # Middleware looked up by :foo returns Faraday::Whatever::Foo. register_middleware foo: Foo end end
Lookup by a constant module Faraday class Whatever # Middleware looked up by : foo returns Faraday :: Whatever :: Foo . register_middleware foo : Foo end end
example
Lookup by a symbol module Faraday class Whatever # Middleware looked up by :bar returns # Faraday::Whatever.const_get(:Bar) register_middleware bar: :Bar end end
Lookup by a symbol module Faraday class Whatever # Middleware looked up by : bar returns # Faraday :: Whatever . const_get ( : Bar ) register_middleware bar : : Bar end end
example
Lookup by a symbol and string in an array module Faraday class Whatever # Middleware looked up by :baz requires 'baz' and returns # Faraday::Whatever.const_get(:Baz) register_middleware baz: [:Baz, 'baz'] end end
Lookup by a symbol and string in an array module Faraday class Whatever # Middleware looked up by : baz requires ' baz ' and returns # Faraday :: Whatever . const_get ( : Baz ) register_middleware baz : [ : Baz ' baz ' ] end end