Class: Faraday::Middleware

Inherits:
Object
  • Object
show all
Extended by:
MiddlewareRegistry
Defined in:
lib/faraday/middleware.rb

Overview

Middleware is the basic base class of any Faraday middleware.

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @app = app
  @options = options
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.


8
9
10
# File 'lib/faraday/middleware.rb', line 8

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.


8
9
10
# File 'lib/faraday/middleware.rb', line 8

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object


15
16
17
18
19
20
# 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
end

#closeObject


22
23
24
25
26
27
28
# File 'lib/faraday/middleware.rb', line 22

def close
  if app.respond_to?(:close)
    app.close
  else
    warn "#{app} does not implement \#close!"
  end
end