climate_control 0.2.0 → 1.0.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 +5 -5
- data/.github/workflows/ci.yml +23 -0
- data/CODE_OF_CONDUCT.md +6 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/NEWS +6 -0
- data/README.md +20 -2
- data/climate_control.gemspec +13 -13
- data/lib/climate_control/environment.rb +4 -7
- data/lib/climate_control/modifier.rb +11 -15
- data/lib/climate_control/version.rb +1 -1
- data/spec/acceptance/climate_control_spec.rb +10 -9
- data/spec/spec_helper.rb +1 -1
- metadata +24 -10
- data/.travis.yml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 65eb94d5a3f27af965178320b8b470c81b36cc646c55eda3b6471db78fca49a4
|
4
|
+
data.tar.gz: ba3abd5ba34a63c23f77195a7f9d4c8e5853f313812dc95b5d9ed37032f964c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a456cc8d8f3fb15cce8bf3401fbbf954b6ad2e7427a20a02fb35abf1da7852833ee8da7862ca4dfa2f98ef9ed62a29841c18d6ab5f40a1d3192073cd73bc621
|
7
|
+
data.tar.gz: 21879ffe4cc583c24fcb7e61fe1617f5126c5f606b4327cc6384cc81dfbff061fff6262c343054dee166f75c109769981354918c2e0481da4412dbf2cf211207
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [pull_request]
|
3
|
+
jobs:
|
4
|
+
tests:
|
5
|
+
name: Tests
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby-version: [3.0, 2.7, 2.6, 2.5]
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
13
|
+
uses: ruby/setup-ruby@v1
|
14
|
+
with:
|
15
|
+
ruby-version: ${{ matrix.ruby-version }}
|
16
|
+
- name: Install gems
|
17
|
+
run: |
|
18
|
+
bundle config path vendor/bundle
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
- name: Run tests
|
21
|
+
run: bundle exec rake
|
22
|
+
- name: Run StandardRB
|
23
|
+
run: bundle exec standardrb
|
data/CODE_OF_CONDUCT.md
ADDED
data/{LICENSE.txt → LICENSE}
RENAMED
data/NEWS
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,24 @@ within a block:
|
|
24
24
|
```ruby
|
25
25
|
ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com' do
|
26
26
|
sign_up_as 'john@example.com'
|
27
|
+
|
28
|
+
confirm_account_for_email 'john@example.com'
|
29
|
+
|
30
|
+
expect(current_email).to bcc_to('confirmation_bcc@example.com')
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
To modify multiple environment variables:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
ClimateControl.modify CONFIRMATION_INSTRUCTIONS_BCC: 'confirmation_bcc@example.com',
|
38
|
+
MAIL_FROM: 'us@example.com' do
|
39
|
+
sign_up_as 'john@example.com'
|
40
|
+
|
27
41
|
confirm_account_for_email 'john@example.com'
|
28
|
-
|
42
|
+
|
43
|
+
expect(current_email).to bcc_to('confirmation_bcc@example.com')
|
44
|
+
expect(current_email).to be_from('us@example.com')
|
29
45
|
end
|
30
46
|
```
|
31
47
|
|
@@ -97,6 +113,8 @@ block, ensuring values are managed properly and consistently.
|
|
97
113
|
4. Push to the branch (`git push origin my-new-feature`)
|
98
114
|
5. Create new Pull Request
|
99
115
|
|
116
|
+
This project uses [StandardRB](https://github.com/testdouble/standard) to ensure formatting.
|
117
|
+
|
100
118
|
## License
|
101
119
|
|
102
|
-
climate_control is copyright 2012-
|
120
|
+
climate_control is copyright 2012-2021 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the [LICENSE](https://github.com/thoughtbot/climate_control/blob/main/LICENSE) file.
|
data/climate_control.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "climate_control/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name
|
8
|
-
gem.version
|
9
|
-
gem.authors
|
10
|
-
gem.email
|
11
|
-
gem.description
|
12
|
-
gem.summary
|
13
|
-
gem.homepage
|
14
|
-
gem.license
|
6
|
+
gem.name = "climate_control"
|
7
|
+
gem.version = ClimateControl::VERSION
|
8
|
+
gem.authors = ["Joshua Clayton"]
|
9
|
+
gem.email = ["joshua.clayton@gmail.com"]
|
10
|
+
gem.description = "Modify your ENV"
|
11
|
+
gem.summary = "Modify your ENV easily with ClimateControl"
|
12
|
+
gem.homepage = "https://github.com/thoughtbot/climate_control"
|
13
|
+
gem.license = "MIT"
|
15
14
|
|
16
|
-
gem.files
|
17
|
-
gem.test_files
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
17
|
gem.require_paths = ["lib"]
|
19
18
|
|
20
|
-
gem.add_development_dependency "rspec", "~> 3.
|
21
|
-
gem.add_development_dependency "rake", "~>
|
19
|
+
gem.add_development_dependency "rspec", "~> 3.10.0"
|
20
|
+
gem.add_development_dependency "rake", "~> 12.3.3"
|
22
21
|
gem.add_development_dependency "simplecov", "~> 0.9.1"
|
22
|
+
gem.add_development_dependency "standard", "~> 1.0.0"
|
23
23
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "thread"
|
2
1
|
require "forwardable"
|
3
2
|
|
4
3
|
module ClimateControl
|
@@ -18,12 +17,10 @@ module ClimateControl
|
|
18
17
|
end
|
19
18
|
|
20
19
|
@semaphore.synchronize do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@owner = nil
|
26
|
-
end
|
20
|
+
@owner = Thread.current
|
21
|
+
yield if block_given?
|
22
|
+
ensure
|
23
|
+
@owner = nil
|
27
24
|
end
|
28
25
|
end
|
29
26
|
|
@@ -8,14 +8,12 @@ module ClimateControl
|
|
8
8
|
|
9
9
|
def process
|
10
10
|
@env.synchronize do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
revert_changed_keys
|
18
|
-
end
|
11
|
+
prepare_environment_for_block
|
12
|
+
run_block
|
13
|
+
ensure
|
14
|
+
cache_environment_after_block
|
15
|
+
delete_keys_that_do_not_belong
|
16
|
+
revert_changed_keys
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -33,12 +31,10 @@ module ClimateControl
|
|
33
31
|
|
34
32
|
def copy_overrides_to_environment
|
35
33
|
@environment_overrides.each do |key, value|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
"attempted to assign #{value} to #{key} but failed (#{e.message})"
|
41
|
-
end
|
34
|
+
@env[key] = value
|
35
|
+
rescue TypeError => e
|
36
|
+
raise UnassignableValueError,
|
37
|
+
"attempted to assign #{value} to #{key} but failed (#{e.message})"
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
@@ -55,7 +51,7 @@ module ClimateControl
|
|
55
51
|
end
|
56
52
|
|
57
53
|
def delete_keys_that_do_not_belong
|
58
|
-
(keys_to_remove - keys_changed_by_block).each {|key| @env.delete(key) }
|
54
|
+
(keys_to_remove - keys_changed_by_block).each { |key| @env.delete(key) }
|
59
55
|
end
|
60
56
|
|
61
57
|
def revert_changed_keys
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
+
Thing = Class.new
|
4
|
+
|
3
5
|
describe "Climate control" do
|
4
6
|
it "allows modification of the environment" do
|
5
7
|
block_run = false
|
@@ -87,22 +89,22 @@ describe "Climate control" do
|
|
87
89
|
# 0.25s passes
|
88
90
|
# [other_thread] thread resolves, FOO is removed, BAZ is copied back to ENV
|
89
91
|
|
90
|
-
thread_removing_env = Thread.new
|
92
|
+
thread_removing_env = Thread.new {
|
91
93
|
with_modified_env BAZ: "buzz" do
|
92
94
|
sleep 0.5
|
93
95
|
end
|
94
96
|
|
95
97
|
expect(ENV["BAZ"]).to be_nil
|
96
|
-
|
98
|
+
}
|
97
99
|
|
98
|
-
other_thread = Thread.new
|
100
|
+
other_thread = Thread.new {
|
99
101
|
sleep 0.25
|
100
102
|
with_modified_env FOO: "bar" do
|
101
103
|
sleep 0.5
|
102
104
|
end
|
103
105
|
|
104
106
|
expect(ENV["FOO"]).to be_nil
|
105
|
-
|
107
|
+
}
|
106
108
|
|
107
109
|
thread_removing_env.join
|
108
110
|
other_thread.join
|
@@ -112,11 +114,11 @@ describe "Climate control" do
|
|
112
114
|
end
|
113
115
|
|
114
116
|
it "is re-entrant" do
|
115
|
-
ret = with_modified_env(FOO: "foo")
|
117
|
+
ret = with_modified_env(FOO: "foo") {
|
116
118
|
with_modified_env(BAR: "bar") do
|
117
119
|
"bar"
|
118
120
|
end
|
119
|
-
|
121
|
+
}
|
120
122
|
|
121
123
|
expect(ret).to eq("bar")
|
122
124
|
|
@@ -125,12 +127,11 @@ describe "Climate control" do
|
|
125
127
|
end
|
126
128
|
|
127
129
|
it "raises when the value cannot be assigned properly" do
|
128
|
-
Thing = Class.new
|
129
130
|
message = generate_type_error_for_object(Thing.new)
|
130
131
|
|
131
|
-
expect
|
132
|
+
expect {
|
132
133
|
with_modified_env(FOO: Thing.new)
|
133
|
-
|
134
|
+
}.to raise_error ClimateControl::UnassignableValueError, /attempted to assign .*Thing.* to FOO but failed \(#{message}\)$/
|
134
135
|
end
|
135
136
|
|
136
137
|
def with_modified_env(options, &block)
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 1.0.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:
|
11
|
+
date: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.
|
19
|
+
version: 3.10.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.
|
26
|
+
version: 3.10.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: simplecov
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: standard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.0
|
55
69
|
description: Modify your ENV
|
56
70
|
email:
|
57
71
|
- joshua.clayton@gmail.com
|
@@ -59,10 +73,11 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".github/workflows/ci.yml"
|
62
77
|
- ".gitignore"
|
63
|
-
-
|
78
|
+
- CODE_OF_CONDUCT.md
|
64
79
|
- Gemfile
|
65
|
-
- LICENSE
|
80
|
+
- LICENSE
|
66
81
|
- NEWS
|
67
82
|
- README.md
|
68
83
|
- Rakefile
|
@@ -93,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
108
|
- !ruby/object:Gem::Version
|
94
109
|
version: '0'
|
95
110
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.5.2
|
111
|
+
rubygems_version: 3.1.4
|
98
112
|
signing_key:
|
99
113
|
specification_version: 4
|
100
114
|
summary: Modify your ENV easily with ClimateControl
|