From 823109503e15ce2ef330b9b6e6bc4bb09e577e2e Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Wed, 7 Jun 2023 11:19:56 -0300 Subject: [PATCH 1/2] Support ERB syntax in old Ruby versions --- lib/next_rails/bundle_report.rb | 15 ++++++++++++++- next_rails.gemspec | 1 + spec/bundle_report_spec.rb | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/next_rails/bundle_report.rb b/lib/next_rails/bundle_report.rb index 0304f2a..41b7be4 100644 --- a/lib/next_rails/bundle_report.rb +++ b/lib/next_rails/bundle_report.rb @@ -17,6 +17,10 @@ def compatibility(rails_version: nil, include_rails_gems: nil) incompatible_gems_by_state = incompatible_gems.group_by { |gem| gem.state(rails_version) } + puts erb_output(incompatible_gems_by_state, incompatible_gems, rails_version) + end + + def erb_output(incompatible_gems_by_state, incompatible_gems, rails_version) template = <<-ERB <% if incompatible_gems_by_state[:found_compatible] -%> <%= "=> Incompatible with Rails #{rails_version} (with new versions that are compatible):".white.bold %> @@ -49,7 +53,16 @@ def compatibility(rails_version: nil, include_rails_gems: nil) <%= incompatible_gems.length.to_s.red %> gems incompatible with Rails <%= rails_version %> ERB - puts ERB.new(template, trim_mode: "-").result(binding) + erb_version = ERB.version + if erb_version =~ /erb.rb \[([\d\.]+) .*\]/ + erb_version = $1 + end + + if Gem::Version.new(erb_version) < Gem::Version.new("2.2") + ERB.new(template, nil, "-").result(binding) + else + ERB.new(template, trim_mode: "-").result(binding) + end end def gem_header(_gem) diff --git a/next_rails.gemspec b/next_rails.gemspec index 75f3e72..ece5d46 100644 --- a/next_rails.gemspec +++ b/next_rails.gemspec @@ -29,6 +29,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "simplecov", "~> 0.17.1" spec.add_development_dependency "timecop", "~> 0.9.1" + spec.add_development_dependency "byebug" spec.add_development_dependency "rexml", "3.1.7.3" # limited on purpose, new versions don't work with old rubies spec.add_development_dependency "webmock", "3.16.2" # limited on purpose, new versions don't work with old rubies end diff --git a/spec/bundle_report_spec.rb b/spec/bundle_report_spec.rb index 325d986..0882764 100644 --- a/spec/bundle_report_spec.rb +++ b/spec/bundle_report_spec.rb @@ -65,4 +65,13 @@ end end end + + describe ".compatibility" do + describe "output" do + it "returns ERB generated output" do + output = NextRails::BundleReport.erb_output({}, [], 7.0) + expect(output).to match "gems incompatible with Rails 7.0" + end + end + end end From fb343946b4806e1948207ef6543e562eb5927b7a Mon Sep 17 00:00:00 2001 From: Ariel Juodziukynas Date: Fri, 9 Jun 2023 09:49:39 -0300 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e4d874..c845ffa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.2.4...main) * Your changes/patches go here. +- [BUGFIX: Support ERB versions older than 2.2.0](https://github.com/fastruby/next_rails/pull/100) + # v1.2.4 / 2023-04-21 [(commits)](https://github.com/fastruby/next_rails/compare/v1.2.3...v1.2.4) - [BUGFIX: Update the warn method signature to support for Ruby 3]