with_env 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -5
- data/lib/with_env.rb +10 -2
- data/lib/with_env/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cadacf8e6ecc35259d9beaa51e64c41ffee74660
|
4
|
+
data.tar.gz: 3186111444fe4b36f3dd437e0a13ed92078ed218
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a72c3f1dca0c0943b560603d4a0df8a868cfca74b35fa24115603c2927215db131d3078bae82ca2a05f7eb73410be897c0a6486a667965b2911a1de619110855
|
7
|
+
data.tar.gz: 637e8b9f3f3fe687fcce19fa2d93c44fd3ba004d717801b29f447d76692c2fe2963b72d5fb4cea84a8f82e68ca07eb13624f978b1f2cbca0785ac694e0b9d0a5
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# WithEnv
|
2
2
|
|
3
|
-
|
3
|
+
WithEnv is an extremely small helper module for executing code with ENV variables. It exists because
|
4
|
+
I got tired of re-writing or copying over a #with_env helper method for the 131st time.
|
4
5
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,7 +22,19 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
```
|
26
|
+
include WithEnv
|
27
|
+
|
28
|
+
with_env("FOO" => "BAR") do
|
29
|
+
`echo $FOO` # => "BAR\n"
|
30
|
+
ENV["FOO"] # => "BAR"
|
31
|
+
end
|
32
|
+
|
33
|
+
# The ENV has been restored to what it was before the
|
34
|
+
# above with_env block, so FOO no longer exists
|
35
|
+
`echo $FOO` # => "\n"
|
36
|
+
ENV.has_key?("FOO") # => false
|
37
|
+
```
|
26
38
|
|
27
39
|
## Development
|
28
40
|
|
@@ -32,10 +44,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
44
|
|
33
45
|
## Contributing
|
34
46
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mhs/with_env-rb.
|
36
48
|
|
37
49
|
|
38
50
|
## License
|
39
51
|
|
40
52
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/lib/with_env.rb
CHANGED
@@ -4,10 +4,18 @@ module WithEnv
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def with_env(env, &blk)
|
7
|
-
before =
|
7
|
+
before = ENV.to_h.dup
|
8
8
|
env.each { |k, v| ENV[k] = v }
|
9
9
|
yield
|
10
10
|
ensure
|
11
|
-
before
|
11
|
+
ENV.replace(before)
|
12
|
+
end
|
13
|
+
|
14
|
+
def without_env(*keys, &blk)
|
15
|
+
before = ENV.to_h.dup
|
16
|
+
keys.flatten.each { |k| ENV.delete(k) }
|
17
|
+
yield
|
18
|
+
ensure
|
19
|
+
ENV.replace(before)
|
12
20
|
end
|
13
21
|
end
|
data/lib/with_env/version.rb
CHANGED