Sha256: 81b48c5d10126940d31fd82e20a1fa25159dfbc35f645f140f738c746bd2950d

Contents?: true

Size: 736 Bytes

Versions: 71

Compression:

Stored size: 736 Bytes

Contents

# frozen_string_literal: true

module Faraday
  # DependencyLoader helps Faraday adapters and middleware load dependencies.
  module DependencyLoader
    attr_reader :load_error

    # Executes a block which should try to require and reference dependent
    # libraries
    def dependency(lib = nil)
      lib ? require(lib) : yield
    rescue LoadError, NameError => e
      self.load_error = e
    end

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

      super
    end

    def loaded?
      load_error.nil?
    end

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

    private

    attr_writer :load_error
  end
end

Version data entries

71 entries across 62 versions & 14 rubygems

Version Path
faraday-1.8.0 lib/faraday/dependency_loader.rb
faraday-1.7.2 lib/faraday/dependency_loader.rb
faraday-1.7.1 lib/faraday/dependency_loader.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/lib/faraday/dependency_loader.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/faraday-1.7.0/lib/faraday/dependency_loader.rb
mx-platform-ruby-0.4.0 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/lib/faraday/dependency_loader.rb
mx-platform-ruby-0.3.2 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/lib/faraday/dependency_loader.rb
mx-platform-ruby-0.3.1 vendor/bundle/ruby/2.6.0/gems/faraday-1.7.0/lib/faraday/dependency_loader.rb
faraday-1.7.0 lib/faraday/dependency_loader.rb
faraday-1.6.0 lib/faraday/dependency_loader.rb
faraday-1.5.1 lib/faraday/dependency_loader.rb
faraday-1.5.0 lib/faraday/dependency_loader.rb
faraday-1.4.3 lib/faraday/dependency_loader.rb
passbase-1.3.0 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/lib/faraday/dependency_loader.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/faraday-1.4.2/lib/faraday/dependency_loader.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/lib/faraday/dependency_loader.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/faraday-1.4.2/lib/faraday/dependency_loader.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/faraday-1.3.0/lib/faraday/dependency_loader.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/faraday-1.2.0/lib/faraday/dependency_loader.rb
faraday-1.4.2 lib/faraday/dependency_loader.rb