lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.73k stars 976 forks source link

NoMethodError: undefined method `dependency` for `Faraday::Middleware:Class` #1397

Closed AlexWayfer closed 2 years ago

AlexWayfer commented 2 years ago

Basic Info

Issue description

I'm trying to update my faraday-encode_xml middleware to Faraday v2, but I've faced the issue which is not described in the UPGRADING.md.

Steps to reproduce

# frozen_string_literal: true

require 'faraday'

module Faraday
  module EncodeXML
    class Middleware < Faraday::Middleware
      dependency do
        require 'gyoku' unless defined?(::Gyoku)
      end
    end
  end
end
olleolleolle commented 2 years ago

The Faraday 2 variant does not do "optional, late-fetched dependencies". It uses a regular require at the top of the file.

olleolleolle commented 2 years ago

@AlexWayfer In order to have the information in the UPGRADING.md, I made a PR. Thanks for the inspiration!