Skip to content

Commit

Permalink
chore: Make rails-autoscale-* gems wrappers around judoscale-*, simpl…
Browse files Browse the repository at this point in the history
…ify requires & gemspecs (#209)

* Use `require_relative` in gemspecs

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.

* Make rails-autoscale-* require judoscale-* base lib file

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.

* Make rails-autoscale-* depend sole on their judoscale-* counterpart

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.

* Further simplify judoscale-* and rails-autoscale-* spec files

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.)

* Remove required Ruby version from rails-autoscale* gemspecs

Let judoscale-* gemspecs define that, since the rails-autoscale-*
depends on them, they'll follow/honor the same required Ruby version.
  • Loading branch information
carlosantoniodasilva authored May 13, 2024
1 parent c570ca6 commit e80d504
Show file tree
Hide file tree
Showing 29 changed files with 99 additions and 126 deletions.
8 changes: 4 additions & 4 deletions judoscale-delayed_job/judoscale-delayed_job.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/delayed_job/version"
# frozen_string_literal: true

require_relative "lib/judoscale/delayed_job/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-delayed_job"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-delayed_job/lib/rails-autoscale-delayed_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/delayed_job"
require "judoscale-delayed_job"
13 changes: 5 additions & 8 deletions judoscale-delayed_job/rails-autoscale-delayed_job.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/delayed_job/version"
# frozen_string_literal: true

require_relative "lib/judoscale/delayed_job/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-delayed_job"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::DelayedJob::VERSION
spec.add_dependency "delayed_job_active_record", ">= 4.0"
spec.add_dependency "judoscale-delayed_job", Judoscale::DelayedJob::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-good_job/judoscale-good_job.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/good_job/version"
# frozen_string_literal: true

require_relative "lib/judoscale/good_job/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-good_job"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-good_job/lib/rails-autoscale-good_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/good_job"
require "judoscale-good_job"
13 changes: 5 additions & 8 deletions judoscale-good_job/rails-autoscale-good_job.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/good_job/version"
# frozen_string_literal: true

require_relative "lib/judoscale/good_job/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-good_job"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::GoodJob::VERSION
spec.add_dependency "good_job", ">= 3.0"
spec.add_dependency "judoscale-good_job", Judoscale::GoodJob::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-que/judoscale-que.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/que/version"
# frozen_string_literal: true

require_relative "lib/judoscale/que/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-que"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-que/lib/rails-autoscale-que.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/que"
require "judoscale-que"
13 changes: 5 additions & 8 deletions judoscale-que/rails-autoscale-que.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/que/version"
# frozen_string_literal: true

require_relative "lib/judoscale/que/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-que"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::Que::VERSION
spec.add_dependency "que", ">= 1.0"
spec.add_dependency "judoscale-que", Judoscale::Que::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-rack/judoscale-rack.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/rack/version"
# frozen_string_literal: true

require_relative "lib/judoscale/rack/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-rack"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-rack/lib/rails-autoscale-rack.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/rack"
require "judoscale-rack"
13 changes: 5 additions & 8 deletions judoscale-rack/rails-autoscale-rack.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/rack/version"
# frozen_string_literal: true

require_relative "lib/judoscale/rack/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-rack"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::Rack::VERSION
spec.add_dependency "rack"
spec.add_dependency "judoscale-rack", Judoscale::Rack::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-rails/judoscale-rails.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/rails/version"
# frozen_string_literal: true

require_relative "lib/judoscale/rails/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-rails"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-rails/lib/rails-autoscale-web.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/rails"
require "judoscale-rails"
13 changes: 5 additions & 8 deletions judoscale-rails/rails-autoscale-web.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/rails/version"
# frozen_string_literal: true

require_relative "lib/judoscale/rails/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-web"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::Rails::VERSION
spec.add_dependency "railties"
spec.add_dependency "judoscale-rails", Judoscale::Rails::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-resque/judoscale-resque.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/resque/version"
# frozen_string_literal: true

require_relative "lib/judoscale/resque/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-resque"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-resque/lib/rails-autoscale-resque.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/resque"
require "judoscale-resque"
13 changes: 5 additions & 8 deletions judoscale-resque/rails-autoscale-resque.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/resque/version"
# frozen_string_literal: true

require_relative "lib/judoscale/resque/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-resque"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::Resque::VERSION
spec.add_dependency "resque", ">= 2.0"
spec.add_dependency "judoscale-resque", Judoscale::Resque::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-ruby/judoscale-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/version"
# frozen_string_literal: true

require_relative "lib/judoscale/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-ruby"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
10 changes: 5 additions & 5 deletions judoscale-ruby/rails-autoscale-core.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/version"
# frozen_string_literal: true

require_relative "lib/judoscale/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-core"
Expand All @@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
spec.add_dependency "judoscale-ruby", Judoscale::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-shoryuken/judoscale-shoryuken.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/shoryuken/version"
# frozen_string_literal: true

require_relative "lib/judoscale/shoryuken/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-shoryuken"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-shoryuken/lib/rails-autoscale-shoryuken.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/shoryuken"
require "judoscale-shoryuken"
13 changes: 5 additions & 8 deletions judoscale-shoryuken/rails-autoscale-shoryuken.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/shoryuken/version"
# frozen_string_literal: true

require_relative "lib/judoscale/shoryuken/version"

Gem::Specification.new do |spec|
spec.name = "rails-autoscale-shoryuken"
Expand All @@ -20,11 +20,8 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].select { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"

spec.add_dependency "rails-autoscale-core", Judoscale::Shoryuken::VERSION
spec.add_dependency "shoryuken", ">= 6.0"
spec.add_dependency "judoscale-shoryuken", Judoscale::Shoryuken::VERSION
end
8 changes: 4 additions & 4 deletions judoscale-sidekiq/judoscale-sidekiq.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "judoscale/sidekiq/version"
# frozen_string_literal: true

require_relative "lib/judoscale/sidekiq/version"

Gem::Specification.new do |spec|
spec.name = "judoscale-sidekiq"
Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/judoscale/judoscale-ruby"
}

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir["lib/**/*"].reject { |f| f.match?(%r{rails-autoscale}) }
spec.require_paths = ["lib"]

spec.required_ruby_version = ">= 2.6.0"
Expand Down
2 changes: 1 addition & 1 deletion judoscale-sidekiq/lib/rails-autoscale-sidekiq.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "judoscale/sidekiq"
require "judoscale-sidekiq"
Loading

0 comments on commit e80d504

Please sign in to comment.