Sha256: 4098b4b1e5495b906f180823dea3b1d64fc781f0ed60e386104995d4da30795b

Contents?: true

Size: 854 Bytes

Versions: 48

Compression:

Stored size: 854 Bytes

Contents

module Fig; end;

# Abstract manager of a set of environment variables.
module Fig::EnvironmentVariables
  def initialize(variables_override = nil)
    @variables = variables_override || get_system_environment_variables
  end

  def empty?
    return @variables.empty?
  end

  def keys
    return @variables.keys
  end

  def with_environment
    original_environment = {}
    original_environment.merge!(ENV.to_hash)

    begin
      set_system_environment_variables(@variables)
      yield
    ensure
      ENV.clear
      set_system_environment_variables(original_environment)
    end

    return
  end

  private

  def get_system_environment_variables
    vars = {}
    ENV.each { |key,value| vars[key]=value }

    return vars
  end

  def set_system_environment_variables(variables)
    variables.each { |key, value| ENV[key] = value }
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
fig-1.23.0 lib/fig/environment_variables.rb
fig-1.22.1.beta.1 lib/fig/environment_variables.rb
fig-1.22.0 lib/fig/environment_variables.rb
fig-1.21.1.beta.2 lib/fig/environment_variables.rb
fig-1.21.1.beta.1 lib/fig/environment_variables.rb
fig-1.21.0 lib/fig/environment_variables.rb
fig-1.20.1.beta.1 lib/fig/environment_variables.rb
fig-1.20.0 lib/fig/environment_variables.rb
fig-1.19.0 lib/fig/environment_variables.rb
fig-1.18.0 lib/fig/environment_variables.rb
fig-1.17.0 lib/fig/environment_variables.rb
fig-1.16.1.beta.1 lib/fig/environment_variables.rb
fig-1.16.0 lib/fig/environment_variables.rb
fig-1.15.1.beta.2 lib/fig/environment_variables.rb
fig-1.15.1.beta.1 lib/fig/environment_variables.rb
fig-1.15.0 lib/fig/environment_variables.rb
fig-1.14.0 lib/fig/environment_variables.rb
fig-1.13.0 lib/fig/environment_variables.rb
fig-1.12.0 lib/fig/environment_variables.rb
fig-1.11.0 lib/fig/environment_variables.rb