Class: RrxConfig::Environment
- Inherits:
-
ActiveSupport::StringInquirer
- Object
- ActiveSupport::StringInquirer
- RrxConfig::Environment
- 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
- .get_env ⇒ Object
- .instance ⇒ Object
-
.reset ⇒ Object
Spec helper for testing
env
.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ Environment
constructor
A new instance of Environment.
- #short ⇒ Object
-
#suffix(force = false) ⇒ Object
rubocop:disable Style/OptionalBooleanParameter.
- #validate! ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ Environment
Returns a new instance of Environment.
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_env ⇒ Object
49 50 51 |
# File 'lib/rrx_config/environment.rb', line 49 def get_env Environment.new end |
.instance ⇒ Object
45 46 47 |
# File 'lib/rrx_config/environment.rb', line 45 def instance @env ||= get_env end |
.reset ⇒ Object
Spec helper for testing env
55 56 57 |
# File 'lib/rrx_config/environment.rb', line 55 def reset @env = nil end |
Instance Method Details
#short ⇒ Object
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 |