Class: Utils::ProbeClient::EnvProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/probe_server.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

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ EnvProxy

The initialize method sets up a new instance with the provided server object.

to the instance variable

Parameters:

  • server (UnixSocks::Server)

    the server object to be assigned



186
187
188
# File 'lib/utils/probe_server.rb', line 186

def initialize(server)
  @server = server
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



218
219
220
# File 'lib/utils/probe_server.rb', line 218

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.

Parameters:

  • key (String)

    the environment variable key to retrieve

Returns:

  • (String)

    the value of the specified environment variable



213
214
215
216
# File 'lib/utils/probe_server.rb', line 213

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.

Parameters:

  • key (String)

    the environment variable key to set

  • value (String)

    the value to assign to the environment variable

Returns:

  • (String)

    the updated environment variable value returned by the server



200
201
202
203
# File 'lib/utils/probe_server.rb', line 200

def []=(key, value)
  response = @server.transmit_with_response(type: 'set_env', key:, value:)
  response.env
end