Method: Dotenv#restore
- Defined in:
- lib/dotenv.rb
#restore(env = @diff&.a, safe: Thread.current == Thread.main) ⇒ Object
Restore ‘ENV` to a given state
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dotenv.rb', line 77 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 |