Module: Faraday::MiddlewareRegistry
- Included in:
- Adapter, Middleware, Request, Response
- Defined in:
- lib/faraday.rb
Overview
Public: Adds the ability for other modules to register and lookup middleware classes.
Instance Method Summary collapse
-
#lookup_middleware(key) ⇒ Object
Public: Lookup middleware class with a registered Symbol shortcut.
-
#register_middleware(mapping) ⇒ Object
Public: Register middleware class(es) on the current module.
Instance Method Details
#lookup_middleware(key) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/faraday.rb', line 160 def lookup_middleware(key) unless defined? @registered_middleware and found = @registered_middleware[key] raise "#{key.inspect} is not registered on #{self}" end found = @registered_middleware[key] = found.call if found.is_a? Proc found.is_a?(Module) ? found : const_get(found) end |
#register_middleware(mapping) ⇒ Object
Public: Register middleware class(es) on the current module.
mapping - A Hash mapping Symbol keys to classes. Classes can be expressed
as fully qualified constant, or a Proc that will be lazily
called to return the former.
Examples
module Faraday
class Whatever
# Middleware looked up by :foo returns Faraday::Whatever::Foo.
register_middleware :foo => Foo
end
end
Returns nothing.
140 141 142 |
# File 'lib/faraday.rb', line 140 def register_middleware(mapping) (@registered_middleware ||= {}).update(mapping) end |