Class: Faraday::Middleware

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MiddlewareRegistry

lookup_middleware, register_middleware

Constructor Details

#initialize(app = nil) ⇒ Middleware

Returns a new instance of Middleware.



33
34
35
# File 'lib/faraday/middleware.rb', line 33

def initialize(app = nil)
  @app = app
end

Class Attribute Details

.load_errorObject

Returns the value of attribute load_error.



6
7
8
# File 'lib/faraday/middleware.rb', line 6

def load_error
  @load_error
end

Class Method Details

.dependency(lib = nil) ⇒ Object

Executes a block which should try to require and reference dependent libraries



13
14
15
16
17
# File 'lib/faraday/middleware.rb', line 13

def self.dependency(lib = nil)
  lib ? require(lib) : yield
rescue LoadError, NameError => error
  self.load_error = error
end

.inherited(subclass) ⇒ Object



28
29
30
31
# File 'lib/faraday/middleware.rb', line 28

def self.inherited(subclass)
  super
  subclass.send(:load_error=, self.load_error)
end

.loaded?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/faraday/middleware.rb', line 24

def self.loaded?
  load_error.nil?
end

.newObject



19
20
21
22
# File 'lib/faraday/middleware.rb', line 19

def self.new(*)
  raise "missing dependency for #{self}: #{load_error.message}" unless loaded?
  super
end