module Faraday::MiddlewareRegistry
def load_middleware(key)
def load_middleware(key) value = registered_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 end end
def lookup_middleware(key)
-
(Faraday::Error)
- if given key is not registered
Returns:
-
(Class)
- a middleware Class.
Parameters:
-
key
(Symbol
) -- key for the registered middleware.
def lookup_middleware(key) load_middleware(key) || raise(Faraday::Error, "#{key.inspect} is not registered on #{self}") end
def middleware_mutex(&block)
def middleware_mutex(&block) @middleware_mutex ||= Monitor.new @middleware_mutex.synchronize(&block) end
def register_middleware(**mappings)
- Example: Lookup by a constant -
Returns:
-
(void)
-
Parameters:
-
mappings
(Hash
) -- Middleware mappings from a lookup symbol to a middleware class.
def register_middleware(**mappings) middleware_mutex do registered_middleware.update(mappings) end end
def registered_middleware
def registered_middleware @registered_middleware ||= {} end
def unregister_middleware(key)
-
key
(Symbol
) -- key for the registered middleware.
def unregister_middleware(key) registered_middleware.delete(key) end