climate_control 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d6475362f621520ac9b951ad69a1a908e9043a2
4
- data.tar.gz: 2d05f1c2f110479042944de906ca2e77ed9f3674
3
+ metadata.gz: 21d2f4ce1d74f8b2e4650cd7ab4efd3d40dac9d6
4
+ data.tar.gz: d14c7f5bc3b4ae309682f529c0ada07a9a874d9b
5
5
  SHA512:
6
- metadata.gz: 3e9aeadc9e0a01b5da958d1d2b46144b6972f50dece9d7d71fc32b841a9cdeb5c187574644c5f471110284522f94019f8d0df6ef11db1e6ebce86adef3750cc9
7
- data.tar.gz: 207eb3f8c9c71fc4c646a85580a2504bb630a581e29cb464dd8b0fbb38e9fde40421f8e017d6aac10559374b854ec0b5484baaf24e0e2f1ffb1d99728a40f712
6
+ metadata.gz: 1c533460213a9e6a4285c3daa7fade227a4a5a5e4eb9a23e41d6bb06362c60468739476dd916be6b9ec3447b3e155dc1594e0fd89597ae58935acef27b850940
7
+ data.tar.gz: 1a9aefaad845f0cdcb147b77cd176e81c0004d28fa17979aab312d27fe1e5251653902bc6fe05581ccd1ecab49075f122b7d029953c708af350e6ad0809f575d
data/NEWS CHANGED
@@ -1,3 +1,6 @@
1
+ 0.2.0 (May 12, 2017)
2
+ Allow nested environment changes in the same thread
3
+
1
4
  0.1.0 (January 7, 2017)
2
5
  Remove ActiveSupport dependency
3
6
 
@@ -7,10 +7,25 @@ module ClimateControl
7
7
 
8
8
  def initialize
9
9
  @semaphore = Mutex.new
10
+ @owner = nil
10
11
  end
11
12
 
12
13
  def_delegators :env, :[]=, :to_hash, :[], :delete
13
- def_delegator :@semaphore, :synchronize
14
+
15
+ def synchronize
16
+ if @owner == Thread.current
17
+ return yield if block_given?
18
+ end
19
+
20
+ @semaphore.synchronize do
21
+ begin
22
+ @owner = Thread.current
23
+ yield if block_given?
24
+ ensure
25
+ @owner = nil
26
+ end
27
+ end
28
+ end
14
29
 
15
30
  private
16
31
 
@@ -1,3 +1,3 @@
1
1
  module ClimateControl
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -111,6 +111,19 @@ describe "Climate control" do
111
111
  expect(ENV["BAZ"]).to be_nil
112
112
  end
113
113
 
114
+ it "is re-entrant" do
115
+ ret = with_modified_env(FOO: "foo") do
116
+ with_modified_env(BAR: "bar") do
117
+ "bar"
118
+ end
119
+ end
120
+
121
+ expect(ret).to eq("bar")
122
+
123
+ expect(ENV["FOO"]).to be_nil
124
+ expect(ENV["BAR"]).to be_nil
125
+ end
126
+
114
127
  it "raises when the value cannot be assigned properly" do
115
128
  Thing = Class.new
116
129
  message = generate_type_error_for_object(Thing.new)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: climate_control
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Clayton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-07 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.6.4
97
+ rubygems_version: 2.5.2
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Modify your ENV easily with ClimateControl