Module: Faraday::DependencyLoader

Included in:
Adapter, Middleware
Defined in:
lib/faraday/dependency_loader.rb

Overview

DependencyLoader helps Faraday adapters and middleware load dependencies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#load_errorObject

Returns the value of attribute load_error


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

def load_error
  @load_error
end

Instance Method Details

#dependency(lib = nil) ⇒ Object

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


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

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

#inherited(subclass) ⇒ Object


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

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

#loaded?Boolean

Returns:

  • (Boolean)

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

def loaded?
  load_error.nil?
end

#newObject


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

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

  super
end