From f37d2b73cd33ad4d8924561b870043bdd44a923e Mon Sep 17 00:00:00 2001 From: "Marcos G. Zimmermann" Date: Thu, 31 Oct 2024 15:11:57 -0300 Subject: [PATCH] fix: adjust Zeitwerk to properly ignore files --- .github/workflows/specs.yml | 21 +- Gemfile | 2 - Gemfile.lock | 4 +- README.md | 2 + bin/setup | 1 + gemfiles/rails52.gemfile | 5 + gemfiles/rails52.gemfile.lock | 236 ++++++++++++++++ gemfiles/rails61.gemfile | 5 + gemfiles/rails61.gemfile.lock | 254 ++++++++++++++++++ lepus.gemspec | 2 + lib/lepus.rb | 30 +-- lib/lepus/rails/railtie.rb | 2 +- lib/lepus/supervisor.rb | 4 +- .../puma/plugin.rb => puma/plugin/lepus.rb} | 0 14 files changed, 540 insertions(+), 28 deletions(-) create mode 100644 gemfiles/rails52.gemfile create mode 100644 gemfiles/rails52.gemfile.lock create mode 100644 gemfiles/rails61.gemfile create mode 100644 gemfiles/rails61.gemfile.lock rename lib/{lepus/puma/plugin.rb => puma/plugin/lepus.rb} (100%) diff --git a/.github/workflows/specs.yml b/.github/workflows/specs.yml index cf4411b..448965c 100644 --- a/.github/workflows/specs.yml +++ b/.github/workflows/specs.yml @@ -9,6 +9,16 @@ on: jobs: test: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['2.7', '3.0'] + gemfile: + - Gemfile + - gemfiles/rails61.gemfile + name: ${{ matrix.ruby }}-${{ matrix.gemfile }} + env: + BUNDLE_GEMFILE: ${{ matrix.gemfile }} services: rabbitmq: image: rabbitmq:3-management @@ -21,12 +31,11 @@ jobs: - 5672:5672 - 15672:15672 steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true - name: Install dependencies run: bundle install - name: Run tests diff --git a/Gemfile b/Gemfile index 9cfface..f9c01b7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,5 @@ source "https://rubygems.org" -gem "multi_json", "~> 1.15" - # Specify your gem's dependencies in lepus.gemspec gemspec diff --git a/Gemfile.lock b/Gemfile.lock index 636238e..eabaffa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,8 @@ PATH lepus (0.0.1.beta1) bunny concurrent-ruby + multi_json + thor zeitwerk GEM @@ -91,6 +93,7 @@ GEM standard-performance (1.4.0) lint_roller (~> 1.1) rubocop-performance (~> 1.21.0) + thor (1.3.2) unicode-display_width (2.6.0) webmock (3.24.0) addressable (>= 2.8.0) @@ -104,7 +107,6 @@ PLATFORMS DEPENDENCIES dotenv lepus! - multi_json (~> 1.15) pry rspec rubocop diff --git a/README.md b/README.md index f1b0e7e..436c7a7 100644 --- a/README.md +++ b/README.md @@ -195,6 +195,8 @@ We provide a Puma plugin if you want to run the Lepus's supervisor together with plugin :lepus ``` +**Note**: The Puma plugin is only available if you are using Puma 6.x or higher. + ## Development After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. diff --git a/bin/setup b/bin/setup index cf4ad25..9b755f1 100755 --- a/bin/setup +++ b/bin/setup @@ -4,3 +4,4 @@ IFS=$'\n\t' set -vx bundle install +find gemfiles -type f \( -iname "*.gemfile" ! -iname "*.lock" \) -exec bundle install --gemfile {} \; diff --git a/gemfiles/rails52.gemfile b/gemfiles/rails52.gemfile new file mode 100644 index 0000000..fa488ee --- /dev/null +++ b/gemfiles/rails52.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gemspec path: ".." + +gem 'rails', '~> 5.2', '>= 5.2.8.1' diff --git a/gemfiles/rails52.gemfile.lock b/gemfiles/rails52.gemfile.lock new file mode 100644 index 0000000..2712b0a --- /dev/null +++ b/gemfiles/rails52.gemfile.lock @@ -0,0 +1,236 @@ +PATH + remote: .. + specs: + lepus (0.0.1.beta1) + bunny + concurrent-ruby + multi_json + zeitwerk + +GEM + remote: https://rubygems.org/ + specs: + actioncable (5.2.8.1) + actionpack (= 5.2.8.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailer (5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.2.8.1) + actionview (= 5.2.8.1) + activesupport (= 5.2.8.1) + rack (~> 2.0, >= 2.0.8) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.2.8.1) + activesupport (= 5.2.8.1) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.3) + activejob (5.2.8.1) + activesupport (= 5.2.8.1) + globalid (>= 0.3.6) + activemodel (5.2.8.1) + activesupport (= 5.2.8.1) + activerecord (5.2.8.1) + activemodel (= 5.2.8.1) + activesupport (= 5.2.8.1) + arel (>= 9.0) + activestorage (5.2.8.1) + actionpack (= 5.2.8.1) + activerecord (= 5.2.8.1) + marcel (~> 1.0.0) + activesupport (5.2.8.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) + minitest (~> 5.1) + tzinfo (~> 1.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + amq-protocol (2.3.2) + arel (9.0.0) + ast (2.4.2) + bigdecimal (3.1.8) + builder (3.3.0) + bunny (2.23.0) + amq-protocol (~> 2.3, >= 2.3.1) + sorted_set (~> 1, >= 1.0.2) + coderay (1.1.3) + concurrent-ruby (1.3.4) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + date (3.3.4) + diff-lcs (1.5.1) + dotenv (2.8.1) + erubi (1.13.0) + globalid (1.1.0) + activesupport (>= 5.0) + hashdiff (1.1.1) + i18n (1.14.6) + concurrent-ruby (~> 1.0) + json (2.7.5) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.23.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (5.25.1) + multi_json (1.15.0) + net-imap (0.4.17) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.4) + nokogiri (1.15.6-x86_64-linux) + racc (~> 1.4) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (5.1.1) + racc (1.8.1) + rack (2.2.10) + rack-test (2.1.0) + rack (>= 1.3) + rails (5.2.8.1) + actioncable (= 5.2.8.1) + actionmailer (= 5.2.8.1) + actionpack (= 5.2.8.1) + actionview (= 5.2.8.1) + activejob (= 5.2.8.1) + activemodel (= 5.2.8.1) + activerecord (= 5.2.8.1) + activestorage (= 5.2.8.1) + activesupport (= 5.2.8.1) + bundler (>= 1.3.0) + railties (= 5.2.8.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (5.2.8.1) + actionpack (= 5.2.8.1) + activesupport (= 5.2.8.1) + method_source + rake (>= 0.8.7) + thor (>= 0.19.0, < 2.0) + rainbow (3.1.1) + rake (13.2.1) + rbtree (0.4.6) + regexp_parser (2.9.2) + rexml (3.3.9) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.33.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (3.2.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + set (1.0.4) + sorted_set (1.0.3) + rbtree + set (~> 1.0) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) + sprockets (>= 3.0.0) + standard (1.37.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + thor (1.3.2) + thread_safe (0.3.6) + timeout (0.4.1) + tzinfo (1.2.11) + thread_safe (~> 0.1) + unicode-display_width (2.6.0) + webmock (3.24.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.18) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + dotenv + lepus! + pry + rails (~> 5.2, >= 5.2.8.1) + rspec + rubocop + rubocop-performance + rubocop-rspec + standard + webmock + +BUNDLED WITH + 2.3.22 diff --git a/gemfiles/rails61.gemfile b/gemfiles/rails61.gemfile new file mode 100644 index 0000000..38e2e2a --- /dev/null +++ b/gemfiles/rails61.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gemspec path: ".." + +gem 'rails', '~> 6.1', '>= 6.1.7.10' diff --git a/gemfiles/rails61.gemfile.lock b/gemfiles/rails61.gemfile.lock new file mode 100644 index 0000000..3fa63a5 --- /dev/null +++ b/gemfiles/rails61.gemfile.lock @@ -0,0 +1,254 @@ +PATH + remote: .. + specs: + lepus (0.0.1.beta1) + bunny + concurrent-ruby + multi_json + zeitwerk + +GEM + remote: https://rubygems.org/ + specs: + actioncable (6.1.7.10) + actionpack (= 6.1.7.10) + activesupport (= 6.1.7.10) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (6.1.7.10) + actionpack (= 6.1.7.10) + activejob (= 6.1.7.10) + activerecord (= 6.1.7.10) + activestorage (= 6.1.7.10) + activesupport (= 6.1.7.10) + mail (>= 2.7.1) + actionmailer (6.1.7.10) + actionpack (= 6.1.7.10) + actionview (= 6.1.7.10) + activejob (= 6.1.7.10) + activesupport (= 6.1.7.10) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (6.1.7.10) + actionview (= 6.1.7.10) + activesupport (= 6.1.7.10) + rack (~> 2.0, >= 2.0.9) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (6.1.7.10) + actionpack (= 6.1.7.10) + activerecord (= 6.1.7.10) + activestorage (= 6.1.7.10) + activesupport (= 6.1.7.10) + nokogiri (>= 1.8.5) + actionview (6.1.7.10) + activesupport (= 6.1.7.10) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (6.1.7.10) + activesupport (= 6.1.7.10) + globalid (>= 0.3.6) + activemodel (6.1.7.10) + activesupport (= 6.1.7.10) + activerecord (6.1.7.10) + activemodel (= 6.1.7.10) + activesupport (= 6.1.7.10) + activestorage (6.1.7.10) + actionpack (= 6.1.7.10) + activejob (= 6.1.7.10) + activerecord (= 6.1.7.10) + activesupport (= 6.1.7.10) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (6.1.7.10) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + amq-protocol (2.3.2) + ast (2.4.2) + bigdecimal (3.1.8) + builder (3.3.0) + bunny (2.23.0) + amq-protocol (~> 2.3, >= 2.3.1) + sorted_set (~> 1, >= 1.0.2) + coderay (1.1.3) + concurrent-ruby (1.3.4) + crack (1.0.0) + bigdecimal + rexml + crass (1.0.6) + date (3.3.4) + diff-lcs (1.5.1) + dotenv (2.8.1) + erubi (1.13.0) + globalid (1.2.1) + activesupport (>= 6.1) + hashdiff (1.1.1) + i18n (1.14.6) + concurrent-ruby (~> 1.0) + json (2.7.5) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.23.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + method_source (1.1.0) + mini_mime (1.1.5) + minitest (5.25.1) + multi_json (1.15.0) + net-imap (0.4.17) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-smtp (0.5.0) + net-protocol + nio4r (2.7.4) + nokogiri (1.15.6-x86_64-linux) + racc (~> 1.4) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (5.1.1) + racc (1.8.1) + rack (2.2.10) + rack-test (2.1.0) + rack (>= 1.3) + rails (6.1.7.10) + actioncable (= 6.1.7.10) + actionmailbox (= 6.1.7.10) + actionmailer (= 6.1.7.10) + actionpack (= 6.1.7.10) + actiontext (= 6.1.7.10) + actionview (= 6.1.7.10) + activejob (= 6.1.7.10) + activemodel (= 6.1.7.10) + activerecord (= 6.1.7.10) + activestorage (= 6.1.7.10) + activesupport (= 6.1.7.10) + bundler (>= 1.15.0) + railties (= 6.1.7.10) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (6.1.7.10) + actionpack (= 6.1.7.10) + activesupport (= 6.1.7.10) + method_source + rake (>= 12.2) + thor (~> 1.0) + rainbow (3.1.1) + rake (13.2.1) + rbtree (0.4.6) + regexp_parser (2.9.2) + rexml (3.3.9) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.33.0) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (3.2.0) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + set (1.0.4) + sorted_set (1.0.3) + rbtree + set (~> 1.0) + sprockets (4.2.1) + concurrent-ruby (~> 1.0) + rack (>= 2.2.4, < 4) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + sprockets (>= 3.0.0) + standard (1.37.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.64.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.4) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.4.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.21.0) + thor (1.3.2) + timeout (0.4.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.6.0) + webmock (3.24.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + websocket-driver (0.7.6) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.18) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + dotenv + lepus! + pry + rails (~> 6.1, >= 6.1.7.10) + rspec + rubocop + rubocop-performance + rubocop-rspec + standard + webmock + +BUNDLED WITH + 2.3.22 diff --git a/lepus.gemspec b/lepus.gemspec index 09b0941..338e2ab 100644 --- a/lepus.gemspec +++ b/lepus.gemspec @@ -37,8 +37,10 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "bunny", ">= 0.0.0" + spec.add_dependency "thor", ">= 0.0.0" spec.add_dependency "zeitwerk", ">= 0.0.0" spec.add_dependency "concurrent-ruby", ">= 0.0.0" + spec.add_dependency "multi_json", ">= 0.0.0" spec.add_development_dependency "dotenv" spec.add_development_dependency "pry" diff --git a/lib/lepus.rb b/lib/lepus.rb index 7f5b684..2afe342 100644 --- a/lib/lepus.rb +++ b/lib/lepus.rb @@ -12,6 +12,19 @@ require "yaml" require "zeitwerk" +loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false) +loader.inflector.inflect "json" => "JSON" +loader.inflector.inflect "cli" => "CLI" +loader.collapse("#{__dir__}/lepus/rails.rb") +loader.collapse("#{__dir__}/lepus/rails/*") +loader.ignore("#{__dir__}/puma") +loader.ignore("#{__dir__}/lepus/rails") +loader.ignore("#{__dir__}/lepus/rails.rb") +loader.ignore("#{__dir__}/lepus/cli.rb") +loader.ignore("#{__dir__}/lepus/middlewares") +loader.log! if ENV["DEBUG"] +loader.setup + module Lepus DEFAULT_LOGGER = Logger.new($stdout) @@ -65,17 +78,6 @@ def initialize(last_heartbeat_at) extend self - def loader - @loader ||= Zeitwerk::Loader.for_gem(warn_on_extra_files: false).tap do |loader| - loader.inflector.inflect "json" => "JSON" - loader.inflector.inflect "cli" => "CLI" - loader.ignore("#{__dir__}/rails") - loader.ignore("#{__dir__}/puma") - loader.ignore("#{__dir__}/cli") - loader.ignore("#{__dir__}/middlewares") - end - end - def logger @logger ||= DEFAULT_LOGGER end @@ -110,14 +112,10 @@ def self.config def self.configure yield config end - - loader.setup end if defined?(::Rails) require_relative "lepus/rails" end -# if defined?(Puma) -# require_relative "lepus/puma/plugin" -# end +# loader.eager_load diff --git a/lib/lepus/rails/railtie.rb b/lib/lepus/rails/railtie.rb index 9de60f0..4cb42b7 100644 --- a/lib/lepus/rails/railtie.rb +++ b/lib/lepus/rails/railtie.rb @@ -27,5 +27,5 @@ class Railtie < ::Rails::Railtie end end - # ActiveSupport.run_load_hooks(:lepus, Lepus) + ActiveSupport.run_load_hooks(:lepus, self) end diff --git a/lib/lepus/supervisor.rb b/lib/lepus/supervisor.rb index 3272687..06ed697 100644 --- a/lib/lepus/supervisor.rb +++ b/lib/lepus/supervisor.rb @@ -55,7 +55,7 @@ def boot begin require "rails" require_relative "rails" - Kernel.require File.expand_path("config/environment", Dir.pwd) + require File.expand_path("config/environment", Dir.pwd) rescue LoadError # Rails not found end @@ -80,7 +80,7 @@ def supervise unless stopped? reap_and_replace_terminated_forks - interruptible_sleep(1.second) + interruptible_sleep(1) end end ensure diff --git a/lib/lepus/puma/plugin.rb b/lib/puma/plugin/lepus.rb similarity index 100% rename from lib/lepus/puma/plugin.rb rename to lib/puma/plugin/lepus.rb