Class: RrxConfig::Environment

Inherits:
ActiveSupport::StringInquirer
  • Object
show all
Defined in:
lib/rrx_config/environment.rb

Constant Summary collapse

RRX_ENVIRONMENT_VARIABLE =
'RRX_ENVIRONMENT'
RRX_ENVIRONMENT_DEFAULT =
'development'
SHORT_NAMES =
{
  'development' => 'dev',
  'staging'     => 'stg',
  'production'  => 'prd'
}.freeze
LONG_NAMES =
SHORT_NAMES.invert.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ Environment

Returns a new instance of Environment.

Parameters:

  • name (String, nil) (defaults to: nil)

    Deployment environment name



24
25
26
27
28
29
30
# File 'lib/rrx_config/environment.rb', line 24

def initialize(name = nil)
  value = normalize(name || from_env)
  super(value)
  validate!
  @force_suffix = "-#{short}"
  @suffix = production? ? '' : @force_suffix
end

Class Method Details

.get_envObject



49
50
51
# File 'lib/rrx_config/environment.rb', line 49

def get_env
  Environment.new
end

.instanceObject



45
46
47
# File 'lib/rrx_config/environment.rb', line 45

def instance
  @env ||= get_env
end

.resetObject

Spec helper for testing env



55
56
57
# File 'lib/rrx_config/environment.rb', line 55

def reset
  @env = nil
end

Instance Method Details

#shortObject



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

def short
  SHORT_NAMES[to_s]
end

#suffix(force = false) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



36
37
38
# File 'lib/rrx_config/environment.rb', line 36

def suffix(force = false) # rubocop:disable Style/OptionalBooleanParameter
  force ? @force_suffix : @suffix
end

#validate!Object



40
41
42
# File 'lib/rrx_config/environment.rb', line 40

def validate!
  raise RrxConfig::EnvironmentError, self unless SHORT_NAMES.key?(self)
end