Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Faraday 2 #65

Merged
merged 6 commits into from
Sep 29, 2023
Merged

Support Faraday 2 #65

merged 6 commits into from
Sep 29, 2023

Conversation

rossta
Copy link
Contributor

@rossta rossta commented Sep 28, 2023

Problem

netbox-client-ruby is not compatible with Faraday 2.x.

Solution

BREAKING CHANGE

To support for Faraday 2, the explicit dependency on "faraday_middleware" must be dropped. "faraday_middleware" is a deprecated gem designed to work with Faraday 0.x and 1.x but not 2.x.

Netbox Client Ruby uses "faraday_middleware" to process request/response with JSON
encoding/decoding middleware for Faraday 0.x and 1.x. In Faraday 2, JSON middleware is supplied by the Faraday gem.

This change removes "faraday_middleware" as an explicit dependency from the gemspec. It is still however treated as a peer dependency in that Netbox Client Ruby will attempt to require "faraday_middleware" if Faraday < 2 is detected at runtime. A helpful error message is raised if it is not installed.

This is an opinionated change that makes the assumption that Netbox Client Ruby still wants to support Faraday 0.x and 1.x alongside 2.x. How long to continue supporting older versions of Faraday is a question. Also, as Netbox Client Ruby is still pre-1.0, I assume that breaking changes do not necessarily require a major version release per SemVer, but that is worth considering.

Notes

  • In Faraday 2, HTTP adapters are extracted to separate gem. Because tests expect the presence of :net_http_persistent adapter, the "faraday-net_http_persistent" gem is added conditionally for development and CI.

  • A new error class, Error is added to help communicate the load error for "faraday_middleware" originates from Netbox Client Ruby. This is similar to what Faraday does when it cannot load a middleware dependency at runtime.

  • The existing error classes are consolidated in error.rb and made subclasses of Error, which is also consistent with how Faraday handles custom errors.

  • Gemfile.lock is now added to version control. This is based on Bundler's recommendation for using Gemfile in gems, notably, to ensure contributors all have a consistent experience when checking out the gem. We can also now add Gemfile to the new Ruby version matrix in CI and ensure consistency between local and CI.

BREAKING CHANGE: To add support for Faraday 2, the dependency on
"faraday_middleware" must be dropped. Netbox Client Ruby uses
"faraday_middleware" to process request/response with JSON
encoding/decoding middleware for Faraday 0.x and 1.x. In Faraday 2, this
middleware is built-in. Netbox Client Ruby will still attempt to require
"faraday_middleware" to support Faraday 0.x and 1.x and will raise an
error if it is not installed. Users of Netbox Client Ruby must install
"faraday_middleware" separately to continue using with Faraday 0.x or
1.x.
This change also consolidates existing error classes in errors.rb
Provides instructions for users of netbox-client-ruby to handle missing
dependency.
https://bundler.io/guides/faq.html#using-gemfiles-inside-gems

> Q: Should I commit my Gemfile.lock when writing a gem?
>
> A: Yes, you should commit it. The presence of a Gemfile.lock in a gem’s repository ensures that a fresh checkout of the repository uses the exact same set of dependencies every time. We believe this makes repositories more friendly towards new and existing contributors. Ideally, anyone should be able to clone the repo, run bundle install, and have passing tests. If you don’t check in your Gemfile.lock, new contributors can get different versions of your dependencies, and run into failing tests that they don’t know how to fix.
The root Gemfile and Gemfile.lock is updated to use the latest
version of Faraday 1.x.
@thde
Copy link
Member

thde commented Sep 29, 2023

I think keeping support for Faraday 0.x and 1.x as long as it does not create too much work is the way to go 👍🏼 .

@thde thde merged commit 81b2924 into ninech:master Sep 29, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants