From bd2d8ab744ebbaf8cfe7b54fbec6e3559a98520a Mon Sep 17 00:00:00 2001 From: Ben Fritsch Date: Tue, 9 Sep 2025 14:27:37 +0200 Subject: [PATCH] remove deprecated code to handle PLINY_ENV finally making the switch from `PLINY_ENV` to `APP_ENV` to align with Sinatra. See https://github.com/interagent/pliny/issues/277 for some details --- CHANGELOG.md | 6 +++ lib/pliny/config_helpers.rb | 26 +----------- spec/config_helpers_spec.rb | 79 ------------------------------------- 3 files changed, 7 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12961179..cf4a6895 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] + +### Removed + +- Remove deprecated `PLINY_ENV` environment variable support in favor of `APP_ENV` to align with Sinatra conventions (https://github.com/interagent/pliny/pull/373) + ## [1.2.0] - 2025-02-10 ### Added - Add support for Ruby 3.3 and 3.4 ([#366](https://github.com/interagent/pliny/pull/3366)) diff --git a/lib/pliny/config_helpers.rb b/lib/pliny/config_helpers.rb index ed2453cc..490d4d2b 100644 --- a/lib/pliny/config_helpers.rb +++ b/lib/pliny/config_helpers.rb @@ -50,23 +50,13 @@ def array(method = nil) end def rack_env - if env == "development" || env == "test" + if app_env == "development" || app_env == "test" "development" else "deployment" end end - # DEPRECATED: pliny_env is deprecated in favour of app_env. - # See more at https://github.com/interagent/pliny/issues/277 - # - # This method is kept temporary in case it is used somewhere in the app. - def pliny_env - warn "Config.pliny_env is deprecated and will be removed, " \ - "use Config.app_env instead." - env - end - private def cast(value, method) @@ -80,20 +70,6 @@ def create(name, value) instance_eval "def #{name}?; !!@#{name} end", __FILE__, __LINE__ end end - - # This method helps with transition from PLINY_ENV to APP_ENV. - def env - legacy_env || app_env - end - - # PLINY_ENV is deprecated, but it might be still used by someone. - def legacy_env - if ENV.key?("PLINY_ENV") - warn "PLINY_ENV is deprecated in favour of APP_ENV, " \ - "update .env file or application configuration." - ENV["PLINY_ENV"] - end - end end # DEPRECATED: ConfigHelpers was a slightly more primitive version diff --git a/spec/config_helpers_spec.rb b/spec/config_helpers_spec.rb index 9ad59f85..305c1386 100644 --- a/spec/config_helpers_spec.rb +++ b/spec/config_helpers_spec.rb @@ -49,84 +49,5 @@ assert_equal "deployment", config.rack_env end - - context "when legacy PLINY_ENV is still defined" do - before do - ENV["ORIGINAL_PLINY_ENV"] = ENV["PLINY_ENV"] - ENV["PLINY_ENV"] = "staging" - end - - after do - ENV["PLINY_ENV"] = ENV.delete("ORIGINAL_PLINY_ENV") - end - - it "uses PLINY_ENV value instead of APP_ENV" do - config = Class.new do - extend Pliny::CastingConfigHelpers - override :app_env, "development", string - end - - assert_equal "deployment", config.rack_env - end - - it "displays deprecation warning" do - config = Class.new do - extend Pliny::CastingConfigHelpers - override :app_env, "development", string - end - - io = StringIO.new - $stderr = io - config.rack_env - $stderr = STDERR - - assert_includes io.string, "PLINY_ENV is deprecated" - end - end - end - - describe "#pliny_env" do - it "displays deprecation warning if pliny_env is used" do - config = Class.new do - extend Pliny::CastingConfigHelpers - override :app_env, "development", string - end - - io = StringIO.new - $stderr = io - config.pliny_env - $stderr = STDERR - - assert_includes io.string, "Config.pliny_env is deprecated" - end - - it "returns app_env value" do - config = Class.new do - extend Pliny::CastingConfigHelpers - override :app_env, "foo", string - end - - assert_equal "foo", config.pliny_env - end - - context "when legacy PLINY_ENV is still defined" do - before do - ENV["ORIGINAL_PLINY_ENV"] = ENV["PLINY_ENV"] - ENV["PLINY_ENV"] = "staging" - end - - after do - ENV["PLINY_ENV"] = ENV.delete("ORIGINAL_PLINY_ENV") - end - - it "returns PLINY_ENV value" do - config = Class.new do - extend Pliny::CastingConfigHelpers - override :app_env, "development", string - end - - assert_equal "staging", config.pliny_env - end - end end end