From ab0bcfb6b540a4d81b81ee85376bcd6827e7566c Mon Sep 17 00:00:00 2001 From: Kevin Dew Date: Mon, 3 Oct 2022 14:32:08 +0100 Subject: [PATCH] Deprecate the use of Plek.current This method was put in temporarily 10 years ago [1] and has had a todo next to it ever since. We're planning to finally remove this [2] in the 5.0 release so this acts as a warning in the interim. [1]: https://github.com/alphagov/plek/commit/309ef5942a7adcdc6d68a9416fa3267c17a2268f [2]: https://github.com/alphagov/plek/pull/93 --- CHANGELOG.md | 2 ++ lib/plek.rb | 5 ++++- test/plek_test.rb | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a140b71..2e261ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Nothing yet. # 4.1.0 + * Deprecate usage of `Plek.current` this method will be removed in next + major version. This adds a warning for users. * Remove public setter methods for `parent_domain` and `external_domain`. These are not used anywhere so there are no API compatibility issues. * Allow setting `GOVUK_APP_DOMAIN=""` (empty string). Similarly for diff --git a/lib/plek.rb b/lib/plek.rb index 4d03ecc..40f0079 100644 --- a/lib/plek.rb +++ b/lib/plek.rb @@ -144,7 +144,10 @@ class << self # Plek.current.find('foo') # as well as the new style: # Plek.new.find('foo') - alias_method :current, :new + def current(...) + warn "Plek.current is deprecated and will be removed. Use Plek.new or Plek.find instead." + new(...) + end # Convenience wrapper. The same as calling +Plek.new.find+. # @see #find diff --git a/test/plek_test.rb b/test/plek_test.rb index 7202544..7d4ee4e 100644 --- a/test/plek_test.rb +++ b/test/plek_test.rb @@ -75,7 +75,11 @@ def test_should_return_dash_divided_source_in_production def test_should_be_able_to_use_current_for_old_style_calls ClimateControl.modify GOVUK_APP_DOMAIN: "foo.bar.baz" do - assert_equal Plek.new.find("foo"), Plek.current.find("foo") + old_style = nil + assert_output("", "Plek.current is deprecated and will be removed. Use Plek.new or Plek.find instead.\n") do + old_style = Plek.current.find("foo") + end + assert_equal Plek.new.find("foo"), old_style end end