Skip to content

Commit

Permalink
Merge pull request #433 from lotus/translate-rack-env-deployment-into…
Browse files Browse the repository at this point in the history
…-lotus-env-production

Translate RACK_ENV=deployment into LOTUS_ENV=production
  • Loading branch information
jodosha committed Dec 30, 2015
2 parents 8542f4b + 350dbc6 commit 68b579e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
27 changes: 26 additions & 1 deletion lib/lotus/environment.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion test/environment_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 68b579e

Please sign in to comment.