Method: Highway::Runtime::Context#with_modified_env

Defined in:
lib/highway/runtime/context.rb

#with_modified_env(new_env, &block) ⇒ Object

Execute the given block in the scope of overridden ENV variables. After that, old values will be restored.

Parameters:

  • new_env (Hash)

    ENV variables to override.

  • &block (Proc)

    A block to execute.

[View source]

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/highway/runtime/context.rb', line 63

def with_modified_env(new_env, &block)

  old_env = Utilities::hash_map(new_env.keys) { |name|
    [name, ENV[name]]
  }

  new_env.each_pair { |name, value|
    ENV[name] = value
  }

  block.call()

  old_env.each_pair { |name, value|
    ENV[name] = value
  }

end