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

Support ERB syntax in old Ruby versions #100

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
15 changes: 14 additions & 1 deletion lib/next_rails/bundle_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down Expand Up @@ -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\.]+) .*\]/
Copy link
Author

Choose a reason for hiding this comment

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

in older erb versions, the version string was something like erb [2.2.0 2019-10-04] instead of just the version, but it changed in newer versions to just 4.0.0

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)
Expand Down
1 change: 1 addition & 0 deletions next_rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/bundle_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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