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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +58 -11
  3. data/lib/nenv.rb +3 -1
  4. data/lib/nenv/version.rb +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d06558bd1f60f7df4ca005879f7edf5766d39f43
4
- data.tar.gz: b799514f85b409d39b5cc00ed89a75ac40128a2e
3
+ metadata.gz: 206715ae7f773db5e3f4f38a3883e452d9663023
4
+ data.tar.gz: 8222926939dc0d449a98b13d394a997c2910663b
5
5
  SHA512:
6
- metadata.gz: 34f8b3b1ba84e8cefded199b13f7aa36bba820455191dcedbb2a6811e2f06f49c39ccaccc8b6e25b20cb10c26bf594db4ccb76a7530cb53d70d27b2fe51e389e
7
- data.tar.gz: 541451121f650f2d099632b0c8d900d5f8d630a78c19aa9245127606f71fb20986f77883532a3d14882b1195d4651fd666e93cb6170b056f5a08eddb700488ba
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 them anyway
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("old data")
253
- allow(ENV).to receive(:[]=).with('MY_VARIABLE', "new data")
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
- let(:env) { instance_double(Nenv::Environment) }
260
- before { allow(Nenv::Environment).to receive(:new).with(:my).and_return(env) }
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
 
@@ -4,7 +4,9 @@ require 'nenv/autoenvironment'
4
4
  require 'nenv/builder'
5
5
 
6
6
  def Nenv(namespace = nil)
7
- Nenv::AutoEnvironment.new(namespace)
7
+ Nenv::AutoEnvironment.new(namespace).tap do |env|
8
+ yield env if block_given?
9
+ end
8
10
  end
9
11
 
10
12
  module Nenv
@@ -1,3 +1,3 @@
1
1
  module Nenv
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.1
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: 2014-12-14 00:00:00.000000000 Z
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.2.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