Class: Faraday::Middleware

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

Overview

Middleware is the basic base class of any Faraday middleware.

Instance Attribute Summary collapse

Attributes included from DependencyLoader

#load_error

Instance Method Summary collapse

Methods included from MiddlewareRegistry

fetch_middleware, load_middleware, lookup_middleware, middleware_mutex, register_middleware, unregister_middleware

Methods included from DependencyLoader

dependency, inherited, loaded?, new

Constructor Details

#initialize(app = nil, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



11
12
13
14
# File 'lib/faraday/middleware.rb', line 11

def initialize(app = nil, options = {})
  @app = app
  @options = options
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



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

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
# File 'lib/faraday/middleware.rb', line 16

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



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

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