nenv 0.1.1 → 0.2.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 +58 -11
- data/lib/nenv.rb +3 -1
- data/lib/nenv/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 206715ae7f773db5e3f4f38a3883e452d9663023
|
4
|
+
data.tar.gz: 8222926939dc0d449a98b13d394a997c2910663b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 765ddaad9d2a4ecb29150945fd016c9314d79e472dd49032b47cda912f47c166faa7710d43eaf46feab31586e3b09e982392ffa9708b65eace8cae231316b5a2
|
7
|
+
data.tar.gz: d014fd2ca1203dc5c1a9537de121d7603e06a42912626abd3eb7d6c33258916ff1e5c377aa0f7f6d746441abfa069e16de017331f12ec57eeeeb54d8fc29e5be
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Other benefits (and compared to other solutions):
|
|
32
32
|
Add this line to your application's Gemfile:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
gem 'nenv'
|
35
|
+
gem 'nenv', '~> 0.1'
|
36
36
|
```
|
37
37
|
|
38
38
|
And then execute:
|
@@ -85,6 +85,16 @@ puts git.pager
|
|
85
85
|
puts git.editor
|
86
86
|
```
|
87
87
|
|
88
|
+
Or in block form
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
Nenv :git do |git|
|
92
|
+
puts git.browser
|
93
|
+
puts git.pager
|
94
|
+
puts git.editor
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
88
98
|
### Custom type handling
|
89
99
|
|
90
100
|
```ruby
|
@@ -231,6 +241,14 @@ env = Nenv::Environment.new(:foo).tap { |e| e.create_method(:bar) }
|
|
231
241
|
all work on the same variable, but each uses a different filter for reading the value.
|
232
242
|
|
233
243
|
|
244
|
+
## Documentation / SemVer / API
|
245
|
+
|
246
|
+
Any behavior not mentioned here (in this README) is subject to change. This
|
247
|
+
includes module names, class names, file names, method names, etc.
|
248
|
+
|
249
|
+
If you are relying on behavior not documented here, please open a ticket.
|
250
|
+
|
251
|
+
|
234
252
|
## What's wrong with ENV?
|
235
253
|
|
236
254
|
Well sure, having ENV act like a Hash is much better than calling "getenv".
|
@@ -242,27 +260,56 @@ Unfortunately, the advantages of using ENV make no sense:
|
|
242
260
|
- it's globally available ... but you can't isolate it in tests (you need to reset it every time)
|
243
261
|
- you can use it to set variables ... but it's named like a const
|
244
262
|
- it allows you to use keys regardless of case ... but by convention lowercase shouldn't be used except for local variables (which are only really used by shell scripts)
|
245
|
-
- it's supposed to look ugly to discourage use ... but often your app/gem is forced to use
|
246
|
-
- it's a simple class ... but either you encapsulate it in your own classes - or all the value mapping/validation happens everywhere you want the data (yuck!)
|
263
|
+
- it's supposed to look ugly to discourage use ... but often your app/gem is forced to use 3rd party environment variables anyway
|
264
|
+
- it's a simple Hash-like class ... but either you encapsulate it in your own classes - or all the value mapping/validation happens everywhere you want the data (yuck!)
|
247
265
|
|
248
266
|
|
249
267
|
But the BIGGEST disadvantage is in specs, e.g.:
|
250
268
|
|
251
269
|
```ruby
|
252
|
-
allow(ENV).to receive(:[]).with('MY_VARIABLE').and_return("
|
253
|
-
allow(ENV).to receive(:[]=).with('MY_VARIABLE', "
|
270
|
+
allow(ENV).to receive(:[]).with('MY_VARIABLE').and_return("foo")
|
271
|
+
allow(ENV).to receive(:[]=).with('MY_VARIABLE', "foo bar")
|
272
|
+
# (and if you get the above wrong, you may be debugging for a long, long time...)
|
254
273
|
```
|
255
274
|
|
256
|
-
which could instead be completely isolated as:
|
275
|
+
which could instead be completely isolated as (and without side effects):
|
257
276
|
|
258
277
|
```ruby
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
allow(env).to receive(:variable).and_return("old data")
|
263
|
-
allow(env).to receive(:variable=).with("new data")
|
278
|
+
allow(env).to receive(:variable).and_return("foo")
|
279
|
+
expect(env).to receive(:variable=).with("foo bar")
|
280
|
+
# (with verifying doubles it's hard to get it wrong and get stuck)
|
264
281
|
```
|
265
282
|
|
283
|
+
Here's a full example:
|
284
|
+
|
285
|
+
```ruby
|
286
|
+
# In your implementation
|
287
|
+
MyEnv = Nenv::Builder.build do
|
288
|
+
create_method(:variable)
|
289
|
+
create_method(:variable=)
|
290
|
+
end
|
291
|
+
|
292
|
+
class Foo
|
293
|
+
def foo
|
294
|
+
MyEnv.new(:my).variable += "bar"
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
# Stubbing the class in your specs
|
299
|
+
RSpec.describe Foo do
|
300
|
+
let(:env) { instance_double(MyEnv) }
|
301
|
+
before { allow(MyEnv).to receive(:new).with(:my).and_return(env) }
|
302
|
+
|
303
|
+
describe "#foo" do
|
304
|
+
before { allow(env).to receive(:variable).and_return("foo") }
|
305
|
+
|
306
|
+
it "appends a value" do
|
307
|
+
expect(env).to receive(:variable=).with("foo bar")
|
308
|
+
subject.foo
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
```
|
266
313
|
|
267
314
|
## Contributing
|
268
315
|
|
data/lib/nenv.rb
CHANGED
data/lib/nenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cezary Baginski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.4.3
|
95
95
|
signing_key:
|
96
96
|
specification_version: 4
|
97
97
|
summary: Convenience wrapper for Ruby's ENV
|