Class: Faraday::Middleware
- Inherits:
-
Object
- Object
- Faraday::Middleware
- Extended by:
- MiddlewareRegistry
- Defined in:
- lib/faraday/middleware.rb
Overview
Middleware is the basic base class of any Faraday middleware.
Direct Known Subclasses
Request::Authorization, Request::Instrumentation, Request::Json, Request::UrlEncoded, Response::Json, Response::Logger, Response::RaiseError
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #close ⇒ Object
-
#initialize(app = nil, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
Methods included from MiddlewareRegistry
lookup_middleware, register_middleware, registered_middleware, unregister_middleware
Constructor Details
#initialize(app = nil, options = {}) ⇒ Middleware
Returns a new instance of Middleware.
10 11 12 13 |
# File 'lib/faraday/middleware.rb', line 10 def initialize(app = nil, = {}) @app = app @options = end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/faraday/middleware.rb', line 8 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/faraday/middleware.rb', line 8 def @options end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/faraday/middleware.rb', line 15 def call(env) on_request(env) if respond_to?(:on_request) app.call(env).on_complete do |environment| on_complete(environment) if respond_to?(:on_complete) end rescue StandardError => e on_error(e) if respond_to?(:on_error) raise end |
#close ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/faraday/middleware.rb', line 25 def close if app.respond_to?(:close) app.close else warn "#{app} does not implement \#close!" end end |