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

Make rails-autoscale-* gems wrappers around judoscale-*, simplify requires & gemspecs #209

Merged
merged 5 commits into from
May 13, 2024

Conversation

carlosantoniodasilva
Copy link
Member

@carlosantoniodasilva carlosantoniodasilva commented May 6, 2024

This simplifies our gem setup to avoid getting judoscale-* and rails-autoscale-* out of sync. This happened recently with good job: #198.

Changes:

  • Make rails-autoscale-* depend on their respective judoscale-* library, leaving judoscale-* handle any additional dependencies.
  • Similarly, remove the Ruby version requirement from rails-autoscale-*, since it should honor judoscale-*.
  • rails-autoscale-* do not require the rails-autoscale-core library anymore, since it should have access to the core via judoscale-* -> judoscale-ruby, and the constant aliasing is there in judoscale-ruby.
  • Each library will only include their respective lib/* files, no longer include Gemfile(s)/Rakefile/gemspec(s).
    • rails-autoscale-* will simply include lib/rails-autoscale-*, and that will require the respective judoscale-* lib now
    • judoscale-* will include everything under lib/*, except files matching rails-autoscale
    • it's essentially partitioning the lib/* files between the two libs.

Stop messing with the load path, use the same approach `bundle gem`
generated gems are using now with `require_relative`, and add the
`frozen_string_literal` pragma as well.
Instead of directly requiring judoscale/* files, make it require the
base judoscale-* lib file, and leave the work of requiring judoscale/*
files to judoscale-* itself.

This is more flexible as it allows judoscale-* to have extra code/setup
if necessary (as it happens with judoscale-ruby for instance, which
rails-autoscale-core is currently requiring), and might allow us to make
rails-autoscale-* gems to be more like shims that depend on judoscale-*
in the future.
The rails-autoscale-* gems will be shims on top of judoscale-* gems,
simply depending on / requiring them going forward.

We only include the rails-autoscale-* files on the gem via gemspec now,
and the specific `version.rb` file for each, since that's necessary for
the dependency / gemspec setup.

This means the judoscale-* gems can now dictate the dependencies without
us having to update both judoscale-* and rails-autoscale-* versions.
Use Ruby's `Dir` to list all files under `lib/`, and partition them
based on whether they match `rails-autoscale` for each lib.

In other words, the judoscale-* libs will get all files that don't match
`rails-autoscale`, while the rails-autoscale-* libs will get all files
that match `rails-autoscale`, which should really only be the main entry
point that delegates back to the respective `judoscale-*` version.

Now for rails-autoscale-* libs, the gemspec lists the matching
judoscale-* library, it will only include the main lib/rails-autoscale*
entrypoint file, which should simply require the respective judoscale-*
file, making the rails-autoscale-* libs simpler shims that wrap the
judoscale-* ones.

This also simplifies the judoscale-* gemspecs to list only the lib/*
files, rather than a few others that were previously included but
weren't necessary. (like Gemfile, Rakefile, gemspecs.)
Let judoscale-* gemspecs define that, since the rails-autoscale-*
depends on them, they'll follow/honor the same required Ruby version.
@carlosantoniodasilva carlosantoniodasilva self-assigned this May 6, 2024
@carlosantoniodasilva carlosantoniodasilva changed the title Make rails-autoscale-* gems wrappers around judoscale-*, simplify gem specs Make rails-autoscale-* gems wrappers around judoscale-*, simplify requires & gemspecs May 6, 2024
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/delayed_job"
require "judoscale-delayed_job"
Copy link
Member Author

Choose a reason for hiding this comment

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

Require the base lib file, instead of directly requiring the inner file. This allows the judoscale lib to determine what needs to be required, and rails-autoscale will simply delegate to that.

@carlosantoniodasilva carlosantoniodasilva marked this pull request as ready for review May 6, 2024 18:05
Copy link
Collaborator

@adamlogic adamlogic left a comment

Choose a reason for hiding this comment

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

Love this clean-up! 🧼

@carlosantoniodasilva carlosantoniodasilva merged commit e80d504 into main May 13, 2024
126 checks passed
@carlosantoniodasilva carlosantoniodasilva deleted the ca-gemspec-improvements branch May 13, 2024 13:30
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.

2 participants