module Dotenv
def restore(env = @diff&.a, safe: Thread.current == Thread.main)
-
safe
(Boolean
) -- Is it safe to modify `ENV`? Defaults to `true` in the main thread, otherwise raises an error. -
env
(Hash
) -- Hash of keys and values to restore, defaults to the last saved state
def restore(env = @diff&.a, safe: Thread.current == Thread.main) # No previously saved or provided state to restore return unless env diff = Dotenv::Diff.new(b: env) return unless diff.any? unless safe raise ThreadError, <<~EOE.tr("\n", " ") Dotenv.restore is not thread safe. Use `Dotenv.modify { }` to update ENV for the duration of the block in a thread safe manner, or call `Dotenv.restore(safe: true)` to ignore this error. EOE end instrument(:restore, diff: diff) { ENV.replace(env) } end