2016-08-06 13:16:09 -04:00
|
|
|
require "rails"
|
2013-10-12 14:27:13 -04:00
|
|
|
|
2012-12-06 07:05:45 -05:00
|
|
|
module EnvHelpers
|
|
|
|
private
|
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def with_rails_env(env)
|
|
|
|
Rails.instance_variable_set :@_env, nil
|
|
|
|
switch_env "RAILS_ENV", env do
|
|
|
|
switch_env "RACK_ENV", nil do
|
|
|
|
yield
|
|
|
|
end
|
2012-12-06 07:05:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def with_rack_env(env)
|
|
|
|
Rails.instance_variable_set :@_env, nil
|
|
|
|
switch_env "RACK_ENV", env do
|
|
|
|
switch_env "RAILS_ENV", nil do
|
|
|
|
yield
|
|
|
|
end
|
2015-03-20 11:14:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:55:02 -04:00
|
|
|
def switch_env(key, value)
|
|
|
|
old, ENV[key] = ENV[key], value
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ENV[key] = old
|
|
|
|
end
|
2012-12-06 07:05:45 -05:00
|
|
|
end
|