lib/slim_lint/utils.rb in slim_lint-0.4.0 vs lib/slim_lint/utils.rb in slim_lint-0.5.0
- old
+ new
@@ -60,7 +60,21 @@
def count_consecutive(items, offset = 0, &block)
count = 1
count += 1 while (offset + count < items.count) && block.call(items[offset + count])
count
end
+
+ # Calls a block of code with a modified set of environment variables,
+ # restoring them once the code has executed.
+ def with_environment(env)
+ old_env = {}
+ env.each do |var, value|
+ old_env[var] = ENV[var.to_s]
+ ENV[var.to_s] = value
+ end
+
+ yield
+ ensure
+ old_env.each { |var, value| ENV[var.to_s] = value }
+ end
end
end