Class: Utils::Probe::ProbeClient::EnvProxy
- Defined in:
- lib/utils/probe/probe_client.rb
Overview
A proxy class for managing environment variables through a probe server communication channel.
This class provides a wrapper around the ENV object that allows setting and retrieving environment variables while logging these operations through the probe server. It intercepts assignments and lookups to provide visibility into environment modifications during probe server operations.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
-
#[](key) ⇒ String
The [] method retrieves the value of an environment variable from the probe server.
-
#[]=(key, value) ⇒ String
The []= method sets an environment variable value through the probe server.
-
#initialize(server) ⇒ EnvProxy
constructor
The initialize method sets up a new instance with the provided server object.
Constructor Details
#initialize(server) ⇒ EnvProxy
The initialize method sets up a new instance with the provided server object.
to the instance variable
23 24 25 |
# File 'lib/utils/probe/probe_client.rb', line 23 def initialize(server) @server = server end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
55 56 57 |
# File 'lib/utils/probe/probe_client.rb', line 55 def env @env end |
Instance Method Details
#[](key) ⇒ String
The [] method retrieves the value of an environment variable from the probe server.
This method sends a request to the probe server to fetch the current value of the specified environment variable key and returns the corresponding value.
50 51 52 53 |
# File 'lib/utils/probe/probe_client.rb', line 50 def [](key) response = @server.transmit_with_response(type: 'get_env', key:) response.env end |
#[]=(key, value) ⇒ String
The []= method sets an environment variable value through the probe server.
This method transmits a request to the probe server to set the specified environment variable key to the given value, then returns the updated environment value from the server’s response.
37 38 39 40 |
# File 'lib/utils/probe/probe_client.rb', line 37 def []=(key, value) response = @server.transmit_with_response(type: 'set_env', key:, value:) response.env end |