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
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

#closeObject



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