permafrost 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5e77f1ee7a485341f34349efe763a02b8242280fce028c06c3077c555efa232
4
+ data.tar.gz: 75646176f44aeed279f9055e88772ce5b0c6c64549dd66e0395efc56271200de
5
+ SHA512:
6
+ metadata.gz: 45e9a7be245204163bc87dd76f8894fd418f62a70a8d73cba5f2387f49eb20da033e515fd5cee7102b495d3dd8b7ed05c1ae85b2a133eb784a104f1b5b862bfa
7
+ data.tar.gz: ae2761008088dc7be3db21b2ed1d660d6924a8faf52bf1fd59eff9c69a90cdfada7bfbdbc94494c9873d5b2aeafbfe23ce1311ffb116f77d15e56f744251f006
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,98 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Include
4
+ - Exclude
5
+
6
+ require:
7
+ - rubocop-performance
8
+ - rubocop-rspec
9
+
10
+ AllCops:
11
+ NewCops: enable
12
+ TargetRubyVersion: 2.7.1
13
+
14
+ Layout/DotPosition:
15
+ EnforcedStyle: trailing
16
+
17
+ Layout/LineLength:
18
+ Enabled: false
19
+
20
+ Layout/MultilineOperationIndentation:
21
+ EnforcedStyle: indented
22
+
23
+ Layout/MultilineMethodCallIndentation:
24
+ EnforcedStyle: indented
25
+
26
+ Layout/ParameterAlignment:
27
+ EnforcedStyle: with_fixed_indentation
28
+
29
+ Metrics/BlockLength:
30
+ Exclude:
31
+ - spec/**/*.rb
32
+
33
+ Naming/PredicateName:
34
+ ForbiddenPrefixes:
35
+ - is_
36
+ - have_
37
+
38
+ # `described_class` makes tests harder to read. When using tools that allow
39
+ # jumping between definitions and the respective tests in a Rails project, or
40
+ # using global search, the class `described_class` refers to might not be clear
41
+ # to the reader. By avoiding the shortcut, we make sure the test stands on its
42
+ # own with as much information as possible.
43
+ RSpec/DescribedClass:
44
+ Enabled: false
45
+
46
+ # Examples should be informative and explicit. While longer examples are
47
+ # generally hard to read, the value should be adjusted as reasonable for a
48
+ # project.
49
+ RSpec/ExampleLength:
50
+ Max: 10
51
+
52
+ # Examples should focus on testing one thing, but that does not necessarily
53
+ # translate into a single expectation. For instance, testing validations in
54
+ # a Rails model should assert (1) the model is invalid, (2) the model has
55
+ # validation errors, and (3) these errors not only include the target field
56
+ # but also the target error message. Another example would be testing
57
+ # side-effects are contained.
58
+ #
59
+ # Similarly, not limiting the number of expectations in an example invites
60
+ # colaborators (and consequently reviewers) to forget the rule of testing one
61
+ # thing only, or to simply ignore it due over the "simplicity" and comfort of
62
+ # checking for everything in a single test.
63
+ #
64
+ # Therefore, this cop should remain enabled, but its value should be adjusted
65
+ # as reasonable for the project.
66
+ #
67
+ RSpec/MultipleExpectations:
68
+ Max: 3
69
+
70
+ Style/ClassAndModuleChildren:
71
+ Enabled: false
72
+
73
+ Style/Documentation:
74
+ Enabled: false
75
+
76
+ Style/FrozenStringLiteralComment:
77
+ Enabled: false
78
+
79
+ Style/IfUnlessModifier:
80
+ Enabled: false
81
+
82
+ Style/NumericLiterals:
83
+ Enabled: false
84
+
85
+ Style/SingleLineBlockParams:
86
+ Enabled: false
87
+
88
+ Style/StringLiterals:
89
+ EnforcedStyle: double_quotes
90
+
91
+ Style/TrailingCommaInArguments:
92
+ EnforcedStyleForMultiline: comma
93
+
94
+ Style/TrailingCommaInArrayLiteral:
95
+ EnforcedStyleForMultiline: comma
96
+
97
+ Style/TrailingCommaInHashLiteral:
98
+ EnforcedStyleForMultiline: comma
@@ -0,0 +1 @@
1
+ ruby 2.7.1
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,19 @@
1
+ Changelog
2
+ =========
3
+
4
+ All notable changes to this project will be documented in this file.
5
+
6
+ The format is based on [Keep a Changelog], and this project adheres to
7
+ [Semantic Versioning].
8
+
9
+
10
+ Unreleased
11
+ ----------
12
+
13
+ - Add `Permafrost.merge` to complement the environment in a limited scope;
14
+ - Add `Permafrost.freeze` to set the environment in a limited scope;
15
+
16
+
17
+ [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
18
+ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html
19
+
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in permafrost.gemspec
4
+ gemspec
5
+
6
+ gem "pry", "~> 0.13.1"
7
+ gem "rake", "~> 12.0"
8
+
9
+ group :test do
10
+ gem "faker", "~> 2.12"
11
+ gem "rspec", "~> 3.0"
12
+ gem "rubocop", "~> 0.85.0"
13
+ gem "rubocop-performance", "~> 1.6"
14
+ gem "rubocop-rspec", "~> 1.39"
15
+ end
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ permafrost (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ concurrent-ruby (1.1.6)
12
+ diff-lcs (1.3)
13
+ faker (2.12.0)
14
+ i18n (>= 1.6, < 2)
15
+ i18n (1.8.2)
16
+ concurrent-ruby (~> 1.0)
17
+ method_source (1.0.0)
18
+ parallel (1.19.1)
19
+ parser (2.7.1.3)
20
+ ast (~> 2.4.0)
21
+ pry (0.13.1)
22
+ coderay (~> 1.1)
23
+ method_source (~> 1.0)
24
+ rainbow (3.0.0)
25
+ rake (12.3.3)
26
+ regexp_parser (1.7.0)
27
+ rexml (3.2.4)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.2)
33
+ rspec-support (~> 3.9.3)
34
+ rspec-expectations (3.9.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.3)
41
+ rubocop (0.85.0)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.7.0.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ regexp_parser (>= 1.7)
46
+ rexml
47
+ rubocop-ast (>= 0.0.3)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 2.0)
50
+ rubocop-ast (0.0.3)
51
+ parser (>= 2.7.0.1)
52
+ rubocop-performance (1.6.0)
53
+ rubocop (>= 0.71.0)
54
+ rubocop-rspec (1.39.0)
55
+ rubocop (>= 0.68.1)
56
+ ruby-progressbar (1.10.1)
57
+ unicode-display_width (1.7.0)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ faker (~> 2.12)
64
+ permafrost!
65
+ pry (~> 0.13.1)
66
+ rake (~> 12.0)
67
+ rspec (~> 3.0)
68
+ rubocop (~> 0.85.0)
69
+ rubocop-performance (~> 1.6)
70
+ rubocop-rspec (~> 1.39)
71
+
72
+ BUNDLED WITH
73
+ 2.1.4
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Subvisual, Lda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,110 @@
1
+ Permafrost
2
+ ==========
3
+
4
+ Freeze the environment (i.e. `ENV`) in a limited scope.
5
+
6
+ Inspired by [Timecop].
7
+
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem "permafrost"
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install permafrost
25
+
26
+
27
+ Usage
28
+ -----
29
+
30
+ Freeze the environment, and change it at will inside a sandbox:
31
+
32
+ ```ruby
33
+ ENV # { "RAILS_ENV" => "production", ... }
34
+
35
+ Permafrost.freeze do
36
+ ENV.clear # {}
37
+ end
38
+
39
+ ENV # { "RAILS_ENV" => "production", ... }
40
+ ```
41
+
42
+ Or, set the environment to use inside the sandbox:
43
+
44
+ ```ruby
45
+ ENV # { "RAILS_ENV" => "production", ... }
46
+
47
+ Permafrost.freeze("foo" => "bar") do
48
+ ENV # { "foo" => "bar" }
49
+ end
50
+
51
+ ENV # { "RAILS_ENV" => "production", ... }
52
+ ```
53
+
54
+ You can also just change something in the environment, leaving the rest as it
55
+ is:
56
+
57
+ ```ruby
58
+ ENV # { "RAILS_ENV" => "production", ... }
59
+
60
+ Permafrost.merge("foo" => "bar") do
61
+ ENV # { "RAILS_ENV" => "production", ..., "foo" => "bar" }
62
+ end
63
+
64
+ ENV # { "RAILS_ENV" => "production", ... }
65
+ ```
66
+
67
+
68
+ Development
69
+ -----------
70
+
71
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
72
+ `rake` to run the linter and tests. You can also run `bin/console` for an interactive
73
+ prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To
76
+ release a new version, update the version number in `version.rb`, and then run
77
+ `bundle exec rake release`, which will create a git tag for the version, push
78
+ git commits and tags, and push the `.gem` file to [rubygems.org].
79
+
80
+
81
+ Contributing
82
+ ------------
83
+
84
+ Bug reports and pull requests are welcome on GitHub at
85
+ https://github.com/subvisual/permafrost.
86
+
87
+
88
+ License
89
+ -----
90
+
91
+ Permafrost is copyright &copy; 2020 Subvisual, Lda.
92
+
93
+ It is open-source, made available for free, and is subject to the terms in
94
+ its [license].
95
+
96
+
97
+ About
98
+ -----
99
+
100
+ Permafrost was created and is maintained with :heart: by
101
+ [Subvisual][subvisual].
102
+
103
+ [![Subvisual][subvisual-logo]][subvisual]
104
+
105
+
106
+ [Timecop]: https://github.com/travisjeffery/timecop
107
+ [license]: ./LICENSE.txt
108
+ [rubygems.org]: https://rubygems.org
109
+ [subvisual]: http://subvisual.com
110
+ [subvisual-logo]: https://raw.githubusercontent.com/subvisual/guides/master/github/templates/logos/blue.png
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:lint)
7
+
8
+ task default: %i[lint spec]
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "permafrost"
5
+ require "pry"
6
+
7
+ Pry.start
@@ -0,0 +1,12 @@
1
+ #!/bin/sh
2
+
3
+ # Exit if any command fails
4
+ set -e
5
+
6
+ # Install required languages
7
+ asdf install
8
+ asdf reshim
9
+
10
+ # Install Ruby dependencies
11
+ bundle install
12
+ asdf reshim ruby
@@ -0,0 +1,57 @@
1
+ require "English"
2
+ require "permafrost/version"
3
+
4
+ module Permafrost
5
+ module ClassMethods
6
+ def freeze(env = nil, &block) # rubocop:disable Metrics/MethodLength
7
+ reader, writer = IO.pipe
8
+ pid = Process.fork
9
+
10
+ if pid.nil?
11
+ reader.close
12
+
13
+ freeze_child(writer, env, &block)
14
+ else
15
+ writer.close
16
+
17
+ freeze_parent(reader, pid)
18
+ end
19
+ ensure
20
+ reader.close
21
+ writer.close
22
+ end
23
+
24
+ def merge(env, &block)
25
+ freeze_env = ENV.to_h.merge(env)
26
+
27
+ freeze(freeze_env, &block)
28
+ end
29
+
30
+ private
31
+
32
+ def freeze_child(write, env)
33
+ ENV.replace(env) unless env.nil?
34
+
35
+ yield
36
+
37
+ Process.exit!(true)
38
+ rescue StandardError => e
39
+ Marshal.dump(e, write)
40
+
41
+ Process.exit!(false)
42
+ end
43
+
44
+ def freeze_parent(_reader, child_pid)
45
+ Process.wait(child_pid)
46
+
47
+ return if $CHILD_STATUS.exitstatus.zero?
48
+
49
+ error_data = read.read
50
+ error = Marshal.load(error_data) # rubocop:disable Security/MarshalLoad
51
+
52
+ raise error
53
+ end
54
+ end
55
+
56
+ extend ClassMethods
57
+ end
@@ -0,0 +1,3 @@
1
+ module Permafrost
2
+ VERSION = "1.0.0".freeze
3
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/permafrost/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "permafrost"
7
+ spec.version = Permafrost::VERSION
8
+ spec.authors = ["Pedro Costa"]
9
+ spec.email = ["pedro@subvisual.com"]
10
+
11
+ spec.summary = "Freeze the environment in a given state."
12
+ spec.description = <<~DESCRIPTION
13
+ Environment variables are a standard way for configuring applications in
14
+ production. It allows for quickly changing the configuration, and avoids
15
+ having to introduce secrets in the code.
16
+
17
+ When testing code that relies on environment variables, it becomes
18
+ problematic to mock the environment, and even more to clean up afterwards.
19
+
20
+ Permafrost allows you to define a limited scope where the environment is
21
+ set as you decide, returning it to its original state afterwards.
22
+ DESCRIPTION
23
+ spec.homepage = "https://github.com/subvisual/permafrost"
24
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
25
+
26
+ spec.metadata["homepage_uri"] = spec.homepage
27
+ spec.metadata["source_code_uri"] = "https://github.com/subvisual/permafrost"
28
+ spec.metadata["changelog_uri"] = "https://github.com/subvisual/permafrost/blob/master/CHANGELOG.md"
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.start_with?("spec") }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: permafrost
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Costa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Environment variables are a standard way for configuring applications in
15
+ production. It allows for quickly changing the configuration, and avoids
16
+ having to introduce secrets in the code.
17
+
18
+ When testing code that relies on environment variables, it becomes
19
+ problematic to mock the environment, and even more to clean up afterwards.
20
+
21
+ Permafrost allows you to define a limited scope where the environment is
22
+ set as you decide, returning it to its original state afterwards.
23
+ email:
24
+ - pedro@subvisual.com
25
+ executables: []
26
+ extensions: []
27
+ extra_rdoc_files: []
28
+ files:
29
+ - ".gitignore"
30
+ - ".rspec"
31
+ - ".rubocop.yml"
32
+ - ".tool-versions"
33
+ - ".travis.yml"
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/console
41
+ - bin/setup
42
+ - lib/permafrost.rb
43
+ - lib/permafrost/version.rb
44
+ - permafrost.gemspec
45
+ homepage: https://github.com/subvisual/permafrost
46
+ licenses: []
47
+ metadata:
48
+ homepage_uri: https://github.com/subvisual/permafrost
49
+ source_code_uri: https://github.com/subvisual/permafrost
50
+ changelog_uri: https://github.com/subvisual/permafrost/blob/master/CHANGELOG.md
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.4.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.1.2
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Freeze the environment in a given state.
70
+ test_files: []