Class: NextStation::Environment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

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

#currentString

Returns the current environment name. Defaults to ‘development’ if none is found.

Returns:

  • (String)


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_namesObject

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_varsObject

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_namesObject

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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


32
33
34
# File 'lib/next_station/environment.rb', line 32

def production?
  production_names.include?(current)
end