Class: NextStation::Environment
- Inherits:
-
Object
- Object
- NextStation::Environment
- Defined in:
- lib/next_station/environment.rb
Overview
Detects the current environment (e.g., development, production) based on a configurable set of environment variables.
Instance Attribute Summary collapse
-
#current ⇒ String
Returns the current environment name.
-
#development_names ⇒ Object
Returns the value of attribute development_names.
-
#env_vars ⇒ Object
Returns the value of attribute env_vars.
-
#production_names ⇒ Object
Returns the value of attribute production_names.
Instance Method Summary collapse
-
#development? ⇒ Boolean
Checks if the current environment is development.
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
-
#production? ⇒ Boolean
Checks if the current environment is production.
Constructor Details
#initialize ⇒ Environment
Returns a new instance of Environment.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/next_station/environment.rb', line 10 def initialize # A list of common environment variables to check for the environment name. @env_vars = %w[RAILS_ENV RACK_ENV APP_ENV RUBY_ENV] # Names that are considered to be a "production" environment. @production_names = %w[production prod prd] # Names that are considered to be a "development" environment. @development_names = %w[development dev] # Manually set environment name. @current = nil end |
Instance Attribute Details
#current ⇒ String
Returns the current environment name. Defaults to ‘development’ if none is found.
26 27 28 |
# File 'lib/next_station/environment.rb', line 26 def current @current || env_vars.map { |var| ENV[var] }.compact.first || 'development' end |
#development_names ⇒ Object
Returns the value of attribute development_names.
7 8 9 |
# File 'lib/next_station/environment.rb', line 7 def development_names @development_names end |
#env_vars ⇒ Object
Returns the value of attribute env_vars.
7 8 9 |
# File 'lib/next_station/environment.rb', line 7 def env_vars @env_vars end |
#production_names ⇒ Object
Returns the value of attribute production_names.
7 8 9 |
# File 'lib/next_station/environment.rb', line 7 def production_names @production_names end |
Instance Method Details
#development? ⇒ Boolean
Checks if the current environment is development.
38 39 40 |
# File 'lib/next_station/environment.rb', line 38 def development? development_names.include?(current) end |
#production? ⇒ Boolean
Checks if the current environment is production.
32 33 34 |
# File 'lib/next_station/environment.rb', line 32 def production? production_names.include?(current) end |