diff --git a/lib/lotus/environment.rb b/lib/lotus/environment.rb index 71346b6d0..963d5a860 100644 --- a/lib/lotus/environment.rb +++ b/lib/lotus/environment.rb @@ -29,6 +29,18 @@ class Environment # @api private DEFAULT_ENV = 'development'.freeze + # Production environment + # + # @since x.x.x + # @api private + PRODUCTION_ENV = 'production'.freeze + + # Rack production environment (aka deployment) + # + # @since x.x.x + # @api private + RACK_ENV_DEPLOYMENT = 'deployment'.freeze + # Default `.env` file name # # @since 0.2.0 @@ -196,13 +208,15 @@ def initialize(options = {}) # # If those are missing it falls back to the defalt one: `"development"`. # + # Rack environment `"deployment"` is translated to Lotus `"production"`. + # # @return [String] the current environment # # @since 0.1.0 # # @see Lotus::Environment::DEFAULT_ENV def environment - @environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV + @environment ||= ENV[LOTUS_ENV] || rack_env || DEFAULT_ENV end # @since 0.3.1 @@ -456,5 +470,16 @@ def set_application_env_vars! def default_host environment == DEFAULT_ENV ? DEFAULT_HOST : LISTEN_ALL_HOST end + + # @since x.x.x + # @api private + def rack_env + case ENV[RACK_ENV] + when RACK_ENV_DEPLOYMENT + PRODUCTION_ENV + else + ENV[RACK_ENV] + end + end end end diff --git a/test/environment_test.rb b/test/environment_test.rb index cff02d665..fa5be9312 100644 --- a/test/environment_test.rb +++ b/test/environment_test.rb @@ -92,7 +92,7 @@ end end - describe "when RACK_ENV is set" do + describe "when RACK_ENV is set to 'production'" do before do ENV['RACK_ENV'] = 'production' @env = Lotus::Environment.new @@ -103,6 +103,17 @@ end end + describe "when RACK_ENV is set to 'deployment'" do + before do + ENV['RACK_ENV'] = 'deployment' + @env = Lotus::Environment.new + end + + it 'returns that value' do + @env.environment.must_equal 'production' + end + end + describe "when none is set" do before do @env = Lotus::Environment.new