vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/lib/faraday/middleware_registry.rb
# 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 register_middleware(autoload_path = nil, mapping = nil)
      if mapping.nil?
        mapping = autoload_path
        autoload_path = nil
      end
      middleware_mutex do
        @middleware_autoload_path = autoload_path if autoload_path
        (@registered_middleware ||= {}).update(mapping)
      end
    end
def register_middleware ( autoload_path = nil , mapping = nil ) if mapping . nil? mapping = autoload_path autoload_path = nil end middleware_mutex do @middleware_autoload_path = autoload_path if autoload_path ( @registered_middleware ||= { } ) . update ( mapping ) end end
Register middleware class(es) on the current module.
Register middleware class ( es ) on the current module .
None
void
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