diff --git a/CHANGELOG.md b/CHANGELOG.md index a7d248e..047d7e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - [BUGFIX: example](https://github.com/fastruby/next_rails/pull/) +- [FEATURE: Add `NextRails.current?` as the inverse of `NextRails.next?`](https://github.com/fastruby/next_rails/pull/174) + * Your changes/patches go here. # v1.4.8 / 2026-03-23 [(commits)](https://github.com/fastruby/next_rails/compare/v1.4.7...v1.4.8) diff --git a/lib/next_rails.rb b/lib/next_rails.rb index 6ccc4ba..80bc7ba 100644 --- a/lib/next_rails.rb +++ b/lib/next_rails.rb @@ -23,6 +23,14 @@ def self.next? @@next_bundle_gemfile = File.exist?(ENV["BUNDLE_GEMFILE"]) && File.basename(ENV["BUNDLE_GEMFILE"]) == "Gemfile.next" end + # This method is the inverse of `NextRails.next?`. It returns true when your + # application is running with the current set of dependencies. + # + # @return [Boolean] + def self.current? + !next? + end + # This method will reset the @@next_bundle_gemfile variable. Then next time # you call `NextRails.next?` it will check the environment once again. def self.reset_next_bundle_gemfile diff --git a/spec/next_rails_spec.rb b/spec/next_rails_spec.rb index 34c0d17..0876d81 100644 --- a/spec/next_rails_spec.rb +++ b/spec/next_rails_spec.rb @@ -51,4 +51,37 @@ end end + describe "NextRails.current?" do + context "when BUNDLE_GEMFILE is not set" do + it "returns true" do + NextRails.reset_next_bundle_gemfile + expect(NextRails.current?).to be_truthy + end + end + + context "when BUNDLE_GEMFILE is set" do + context "when it is set to Gemfile.next" do + it "returns false" do + FileUtils.touch("Gemfile.next") + NextRails.reset_next_bundle_gemfile + + with_env("BUNDLE_GEMFILE" => "Gemfile.next") + expect(NextRails.current?).to be_falsey + end + end + + context "when it is set to something else" do + it "returns true" do + FileUtils.touch("Gemfile4") + NextRails.reset_next_bundle_gemfile + + with_env("BUNDLE_GEMFILE" => "Gemfile4") + expect(NextRails.current?).to be_truthy + + FileUtils.rm("Gemfile4") + end + end + end + end + end