Skip to content

refactor: autoloading via zeitwerk#868

Open
YOU54F wants to merge 2 commits intopact-foundation:masterfrom
YOU54F:refactor/zeitwerk
Open

refactor: autoloading via zeitwerk#868
YOU54F wants to merge 2 commits intopact-foundation:masterfrom
YOU54F:refactor/zeitwerk

Conversation

@YOU54F
Copy link
Copy Markdown
Member

@YOU54F YOU54F commented Nov 3, 2025

fixes #633

Lots of files touched, but mainly the removal of require "pact_broker/.*"

Main loading logic for Zeitwerk is in our gems entrypoint ./lib/pact_broker.rb which follows the pattern

  1. Load zeitwerk germ
  2. We instruct zeitwerk not to warn us about files that are unmanaged by Zeitwerk, these are because we cannot rename or rework the files to work within convention, we just need to manually load these as before
  3. We use Zeitwerk:Loader.for_gem which users the file list in the gemspec to generate a load list of files
  4. We explicitly ignore the files Zeitwerk cannot load, these were identified by commenting out step 2
  5. We call loader.setup to autoload all not ignored files
  6. We manually require pact_broker/webmachine which loads webmachine, and our ignored monkey patches

The rest of the changes are just renaming files/classes/modules to match Zeitwerk conventions, and removal of manual imports which are no longer required, as that is the big benefit of using an autoloader.

@YOU54F YOU54F requested a review from bethesque November 3, 2025 23:45
@YOU54F
Copy link
Copy Markdown
Member Author

YOU54F commented Nov 3, 2025

Yoooo @bethesque!

I had a bit of a go at this, after getting familiarised with Zeitwerk in the pact-ruby v2 rewrite.

Thought you might fancy a goosey gander.

Wasn't too bad in the end actually, probably in part ot the work you have previously done in #661

@YOU54F
Copy link
Copy Markdown
Member Author

YOU54F commented Nov 3, 2025

Hey team!

We may need some coordination, and/or testing with PactFlow prior to merging this in, in case there are changes required to consume, or if we need to plan it in with some engineering time in order to be able to apply this.

@mefellows
Copy link
Copy Markdown
Member

@impurist @pahnin FYI

@YOU54F YOU54F force-pushed the refactor/zeitwerk branch from 8504b12 to 7202234 Compare March 18, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add zeitwerk for file loading

2 participants