class Dotenv::Diff
A diff between multiple states of ENV.
def added
def added b.slice(*(b.keys - a.keys)) end
def any?
def any? [added, removed, changed].any?(&:any?) end
def changed
def changed (b.slice(*a.keys).to_a - a.to_a).map do |(k, v)| [k, [a[k], v]] end.to_h end
def env
def env b.slice(*(added.keys + changed.keys)).merge(removed.transform_values { |v| nil }) end
def initialize(a: snapshot, b: ENV, &block)
- Yield: - a block to execute before recording the final state
Parameters:
-
b
(Hash
) -- the final state, defaults to the current ENV -
a
(Hash
) -- the initial state, defaults to a snapshot of current ENV
def initialize(a: snapshot, b: ENV, &block) @a, @b = a, b block&.call self ensure @b = snapshot if block end
def removed
def removed a.slice(*(a.keys - b.keys)) end
def snapshot
def snapshot # `dup` should not be required here, but some people use `stub_const` to replace ENV with # a `Hash`. This ensures that we get a frozen copy of that instead of freezing the original. # https://github.com/bkeepers/dotenv/issues/482 ENV.to_h.dup.freeze end