climate_control 0.2.0 → 1.0.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
- SHA1:
3
- metadata.gz: 21d2f4ce1d74f8b2e4650cd7ab4efd3d40dac9d6
4
- data.tar.gz: d14c7f5bc3b4ae309682f529c0ada07a9a874d9b
2
+ SHA256:
3
+ metadata.gz: 65eb94d5a3f27af965178320b8b470c81b36cc646c55eda3b6471db78fca49a4
4
+ data.tar.gz: ba3abd5ba34a63c23f77195a7f9d4c8e5853f313812dc95b5d9ed37032f964c8
5
5
  SHA512:
6
- metadata.gz: 1c533460213a9e6a4285c3daa7fade227a4a5a5e4eb9a23e41d6bb06362c60468739476dd916be6b9ec3447b3e155dc1594e0fd89597ae58935acef27b850940
7
- data.tar.gz: 1a9aefaad845f0cdcb147b77cd176e81c0004d28fa17979aab312d27fe1e5251653902bc6fe05581ccd1ecab49075f122b7d029953c708af350e6ad0809f575d
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
@@ -0,0 +1,6 @@
1
+ # Code of Conduct
2
+
3
+ By participating in this project, you agree to abide by the
4
+ [thoughtbot code of conduct][1].
5
+
6
+ [1]: https://thoughtbot.com/open-source-code-of-conduct
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2014 Joshua Clayton and thoughtbot, inc.
1
+ Copyright (c) 2012-2021 Joshua Clayton and thoughtbot, inc.
2
2
 
3
3
  MIT License
4
4
 
data/NEWS CHANGED
@@ -1,3 +1,9 @@
1
+ 1.0.0 (March 6, 2021)
2
+ Commit to supporting latest patch versions of Ruby 2.5+
3
+ Improve documentation
4
+ Format code with StandardRB
5
+ Bump gem dependencies
6
+
1
7
  0.2.0 (May 12, 2017)
2
8
  Allow nested environment changes in the same thread
3
9
 
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
- current_email.should bcc_to('confirmation_bcc@example.com')
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-2017 Joshua Clayton and thoughtbot, inc. It is free software and may be redistributed under the terms specified in the [LICENSE.txt](https://github.com/thoughtbot/climate_control/blob/master/LICENSE.txt) file.
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.
@@ -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 = "climate_control"
8
- gem.version = ClimateControl::VERSION
9
- gem.authors = ["Joshua Clayton"]
10
- gem.email = ["joshua.clayton@gmail.com"]
11
- gem.description = %q{Modify your ENV}
12
- gem.summary = %q{Modify your ENV easily with ClimateControl}
13
- gem.homepage = "https://github.com/thoughtbot/climate_control"
14
- gem.license = "MIT"
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 = `git ls-files`.split($/)
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
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.1.0"
21
- gem.add_development_dependency "rake", "~> 10.3.2"
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
- begin
22
- @owner = Thread.current
23
- yield if block_given?
24
- ensure
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
- begin
12
- prepare_environment_for_block
13
- run_block
14
- ensure
15
- cache_environment_after_block
16
- delete_keys_that_do_not_belong
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
- begin
37
- @env[key] = value
38
- rescue TypeError => e
39
- raise UnassignableValueError,
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,3 +1,3 @@
1
1
  module ClimateControl
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -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 do
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
- end
98
+ }
97
99
 
98
- other_thread = Thread.new do
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
- end
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") do
117
+ ret = with_modified_env(FOO: "foo") {
116
118
  with_modified_env(BAR: "bar") do
117
119
  "bar"
118
120
  end
119
- end
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 do
132
+ expect {
132
133
  with_modified_env(FOO: Thing.new)
133
- end.to raise_error ClimateControl::UnassignableValueError, /attempted to assign .*Thing.* to FOO but failed \(#{message}\)$/
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
@@ -1,5 +1,5 @@
1
1
  begin
2
- require 'simplecov'
2
+ require "simplecov"
3
3
  SimpleCov.start
4
4
  rescue LoadError
5
5
  warn "warning: simplecov gem not found; skipping coverage"
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.2.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: 2017-05-12 00:00:00.000000000 Z
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.1.0
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.1.0
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: 10.3.2
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: 10.3.2
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
- - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
64
79
  - Gemfile
65
- - LICENSE.txt
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
- rubyforge_project:
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
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- rvm:
2
- - 2.2.6
3
- - 2.3.3
4
- - 2.4.0
5
- before_install:
6
- - gem update --system
7
- - gem update bundler
8
- install: "bundle install"
9
- branches:
10
- only:
11
- - master