Class: Unenviable::ENVWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/unenviable/env_wrapper.rb

Overview

Wraps the ENV variable to catch calls to ENV where the value is missing or not specified in Unenviable’s YAML file.

Instance Method Summary collapse

Constructor Details

#initializeENVWrapper

Returns a new instance of ENVWrapper.



5
6
7
8
# File 'lib/unenviable/env_wrapper.rb', line 5

def initialize
  @saved_env = ENV
  @closed = false
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/unenviable/env_wrapper.rb', line 10

def [](key)
  failed "Requested ENV[#{key}] after initialization finished!" if @closed
  value = @saved_env[key]
  fail "Requested ENV[#{key}] which has not been described!" unless Unenviable.described?(key)
  return value unless value.nil?
  'MISSING VALUE'
end

#[]=(key, value) ⇒ Object



18
19
20
# File 'lib/unenviable/env_wrapper.rb', line 18

def []=(key, value)
  @saved_env[key] = value
end

#close_wrapperObject



22
23
24
# File 'lib/unenviable/env_wrapper.rb', line 22

def close_wrapper
  @closed = true
end