Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
eval committed Sep 23, 2014
1 parent 01e1dae commit 5f51d14
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/spring/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,19 @@ def run
end

def with_env_vars(env)
# Delete all env vars which are unchanged from before spring started
original_env.each { |k, v| ENV.delete k if ENV[k] == v }
# Allowed are keys currently not in ENV...
allowed_keys = env.keys - ENV.keys
# ...and ENV-keys whose values have not changed since the start of spring
allowed_keys += original_env.select {|k, v| ENV[k] == v }.keys
# never allowed:
allowed_keys -= %w(RUBYOPT RUBY_ROOT BUNDLE_GEMFILE GEM_ROOT GEM_HOME GEM_PATH)
allowed_keys.uniq!

changed_keys = env.keys - ENV.keys
# Load in the current env vars, except those which *were* changed when spring started
env.each { |k, v| ENV[k] ||= v }
allowed_keys.each{|k| ENV[k] = env[k] }

yield
ensure
changed_keys.each do |k|
allowed_keys.each do |k|
original_env.has_key?(k) ? ENV[k] = original_env[k] : ENV.delete(k)
end
end
Expand Down

0 comments on commit 5f51d14

Please sign in to comment.