Skip to content

refactor: move platform detection to Rake module, and delete Rake::Win32 module#729

Open
pvdb wants to merge 1 commit intoruby:masterfrom
pvdb:simplify_rake_platform_detection
Open

refactor: move platform detection to Rake module, and delete Rake::Win32 module#729
pvdb wants to merge 1 commit intoruby:masterfrom
pvdb:simplify_rake_platform_detection

Conversation

@pvdb
Copy link
Copy Markdown
Contributor

@pvdb pvdb commented Apr 20, 2026

The Rake::Win32 module existed solely to answer one question: are we running on Windows?

That single-method module was more ceremony than it was worth, and it meant platform detection was split across two places — Win32.windows? in win32.rb and Application#unix? in application.rb.

Both methods now live together as Rake.windows? and Rake.unix? on the Rake module itself, which is the natural home for gem-level helpers.

Application#windows? and Application#unix? are kept as thin delegators so nothing calling them through an application instance breaks.

Beyond tidying up the code, the refactoring also untangles two distinct uses of platform detection that were previously conflated. 🎉

The first is a static, load-time concern: deciding which tests to define or which assertions to run. This only needs a simple module-level predicate — call it once when the class loads and you're done.

The second is a dynamic, instance-level concern: branching on platform inside Application methods, and — critically — being stubbable in tests so that platform-specific code paths can be exercised regardless of where CI runs.

These two uses have different requirements.

  1. The new Rake.windows? / Rake.unix? module methods serve the first cleanly.
  2. The delegators on Application preserve the second — including the ability to stub @app.windows? / @app.unix? in tests, which several existing tests rely on.

I hope you like it, @hsbt 🤞 - this isn't just cleanup, it's a separation of concerns that makes the intent of each call site
clearer.

The Rake::Win32 module existed solely to answer one question: are we
running on Windows? That single-method module was more ceremony than it
was worth, and it meant platform detection was split across two places —
Win32.windows? in win32.rb and Application#unix? in application.rb.

Both methods now live together as Rake.windows? and Rake.unix? on the
Rake module itself, which is the natural home for gem-level helpers.

Application#windows? and Application#unix? are kept as thin delegators
so nothing calling them through an application instance breaks.
@pvdb pvdb force-pushed the simplify_rake_platform_detection branch from 9ac65f4 to e4383ab Compare April 20, 2026 17:00
Comment thread test/test_rake.rb
# be both Windows and Unix at the same time
assert ! (Rake.windows? && Rake.unix?)
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This preserves the original TestRakeApplication.test_windows exclusivity check, but - arguably - with a more intent-revealing name, and also by documenting it (as the original assertion was somewhat esoteric) 😃

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.

1 participant