Class: Google::Cloud::Env::Variables
- Inherits:
-
Object
- Object
- Google::Cloud::Env::Variables
- Defined in:
- lib/google/cloud/env/variables.rb
Overview
Access to system environment variables.
This is a hashlike object that controls access to environment variable data. It supports temporarily changing the data source (i.e. swapping ::ENV out for a different set of data) for mocking.
Instance Attribute Summary collapse
-
#backing_data ⇒ Hash{String=>String}
The backing data is a hash or hash-like object that represents the environment variable data.
Instance Method Summary collapse
-
#[](key) ⇒ String?
(also: #get)
Fetch the given environment variable from the backing data.
-
#initialize ⇒ Variables
constructor
Create an enviroment variables access object.
-
#with_backing_data(temp_backing_data) ⇒ Object
Run the given block with the backing data replaced with the given hash.
Constructor Details
#initialize ⇒ Variables
Create an enviroment variables access object. This is initially backed by the actual environment variables (i.e. ENV).
33 34 35 |
# File 'lib/google/cloud/env/variables.rb', line 33 def initialize @backing_data = ::ENV end |
Instance Attribute Details
#backing_data ⇒ Hash{String=>String}
The backing data is a hash or hash-like object that represents the environment variable data. This can either be the actual environment variables object (i.e. ENV) or a substitute hash used for mocking.
55 56 57 |
# File 'lib/google/cloud/env/variables.rb', line 55 def backing_data @backing_data end |
Instance Method Details
#[](key) ⇒ String? Also known as: get
Fetch the given environment variable from the backing data.
43 44 45 |
# File 'lib/google/cloud/env/variables.rb', line 43 def [] key @backing_data[key.to_s] end |
#with_backing_data(temp_backing_data) ⇒ Object
Run the given block with the backing data replaced with the given hash. The original backing data is restored afterward. This is used for debugging/testing/mocking.
64 65 66 67 68 69 70 71 72 |
# File 'lib/google/cloud/env/variables.rb', line 64 def with_backing_data temp_backing_data old_backing_data = @backing_data begin @backing_data = temp_backing_data yield ensure @backing_data = old_backing_data end end |