prius 2.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +60 -0
- data/.github/dependabot.yml +7 -0
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -0
- data/README.md +3 -3
- data/lib/prius/errors.rb +2 -0
- data/lib/prius/railtie.rb +2 -0
- data/lib/prius/registry.rb +15 -0
- data/lib/prius/version.rb +3 -1
- data/lib/prius.rb +3 -1
- data/prius.gemspec +6 -2
- data/spec/prius/registry_spec.rb +39 -1
- metadata +37 -9
- data/.travis.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a4ec85e28d88e7ac3605c1f22d6a71c9d14ec4e25c67cce15fb0655b9e878ea0
|
4
|
+
data.tar.gz: 81451517255e0cb04890cc93a1f39c4848e726019030cc45ccb11f07b7d934e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417aa19312808fac0140c6e052695268ea7291ea2dcec5aae6af3f5ee300e8cfdeb325380380a7b71ebec28b06b9ff127802f310d5e6b680287aaf83b0d49a43
|
7
|
+
data.tar.gz: fdd5adfc03b58811922487ca08e94add9ee99abf19e0840775f58cb1ee93e315787723ce29cd38b99af49904eed2b96aa6cc388fcd6256b33872bbbff17ad9e0
|
@@ -0,0 +1,60 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
references:
|
4
|
+
steps: &steps
|
5
|
+
- checkout
|
6
|
+
|
7
|
+
# CircleCI's Ruby images have Git installed, but the JRuby images lack it, so let's
|
8
|
+
# make sure it's installed
|
9
|
+
- run: apt-get update && apt-get install -y git
|
10
|
+
|
11
|
+
- type: cache-restore
|
12
|
+
key: prius-bundler-{{ checksum "prius.gemspec" }}
|
13
|
+
|
14
|
+
- run: gem install bundler -v 2.0.1
|
15
|
+
|
16
|
+
- run: bundle install --path vendor/bundle
|
17
|
+
|
18
|
+
- type: cache-save
|
19
|
+
key: prius-bundler-{{ checksum "prius.gemspec" }}
|
20
|
+
paths:
|
21
|
+
- vendor/bundle
|
22
|
+
|
23
|
+
- type: shell
|
24
|
+
command: |
|
25
|
+
bundle exec rspec --profile 10 \
|
26
|
+
--format RspecJunitFormatter \
|
27
|
+
--out /tmp/test-results/rspec.xml \
|
28
|
+
--format progress \
|
29
|
+
spec
|
30
|
+
|
31
|
+
- type: store_test_results
|
32
|
+
path: /tmp/test-results
|
33
|
+
|
34
|
+
- run: bundle exec rubocop
|
35
|
+
jobs:
|
36
|
+
build-ruby26:
|
37
|
+
docker:
|
38
|
+
- image: ruby:2.6
|
39
|
+
steps: *steps
|
40
|
+
build-ruby27:
|
41
|
+
docker:
|
42
|
+
- image: ruby:2.7
|
43
|
+
steps: *steps
|
44
|
+
build-ruby3:
|
45
|
+
docker:
|
46
|
+
- image: ruby:3
|
47
|
+
steps: *steps
|
48
|
+
build-jruby93:
|
49
|
+
docker:
|
50
|
+
- image: jruby:9.3
|
51
|
+
steps: *steps
|
52
|
+
|
53
|
+
workflows:
|
54
|
+
version: 2
|
55
|
+
tests:
|
56
|
+
jobs:
|
57
|
+
- build-ruby26
|
58
|
+
- build-ruby27
|
59
|
+
- build-ruby3
|
60
|
+
- build-jruby93
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
# 4.1.0
|
2
|
+
|
3
|
+
* Add support for coercing to a date.
|
4
|
+
|
5
|
+
# 4.0.0
|
6
|
+
|
7
|
+
* Add support for Ruby 3.0
|
8
|
+
* Enforce Ruby 2.6 as minimum required version
|
9
|
+
* Drop support for Ruby 2.2, 2.3, 2.4, 2.5
|
10
|
+
* Drop support for JRuby versions < 9.3.x (implicity enforced by C Ruby version 2.6 as minimum)
|
11
|
+
|
12
|
+
# 3.0.0
|
13
|
+
|
14
|
+
* Enforce Ruby 2.2 as minimum required version
|
15
|
+
* Use CircleCI instead of Travis for CI builds
|
16
|
+
* Add Dependabot support
|
17
|
+
* Some development dependency updates
|
18
|
+
|
1
19
|
# 2.0.0
|
2
20
|
|
3
21
|
* Drop support for Ruby versions 1.9, 2.0, 2.1, and add support for 2.3 and 2.4
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
Environmentally-friendly application config for Ruby.
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/prius.svg)](http://badge.fury.io/rb/prius)
|
5
|
-
[![Build Status](https://
|
5
|
+
[![Build Status](https://circleci.com/gh/gocardless/prius.svg?style=svg)](https://app.circleci.com/pipelines/github/gocardless/prius)
|
6
6
|
|
7
7
|
Prius helps you guarantee that your environment variables are:
|
8
8
|
|
9
9
|
- **Present** - an exception is raised if an environment variable is missing,
|
10
10
|
so you can hear about it as soon as your app boots.
|
11
11
|
- **Valid** - an environment variable can be coerced to a desired type
|
12
|
-
(integer, boolean or
|
12
|
+
(integer, boolean, string, or date), and an exception will be raised if the value
|
13
13
|
doesn't match the type.
|
14
14
|
|
15
15
|
## Usage
|
@@ -60,7 +60,7 @@ If an environment variable can't be loaded, Prius will raise one of:
|
|
60
60
|
| Param | Default | Description |
|
61
61
|
|-------------------|---------------|-------------------------------------------------------------------------------------------|
|
62
62
|
| `required` | `true` | Flag to require the environment variable to have been set. |
|
63
|
-
| `type` | `:string` | Type to coerce the environment variable to. Allowed values are `:string`, `:int
|
63
|
+
| `type` | `:string` | Type to coerce the environment variable to. Allowed values are `:string`, `:int`, `:bool`, and `:date`. |
|
64
64
|
| `env_var` | `name.upcase` | Name of the environment variable name (if different from the upcased `name`). |
|
65
65
|
|
66
66
|
#### Reading Environment Variables
|
data/lib/prius/errors.rb
CHANGED
data/lib/prius/railtie.rb
CHANGED
data/lib/prius/registry.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "prius/errors"
|
2
4
|
|
3
5
|
module Prius
|
@@ -20,6 +22,7 @@ module Prius
|
|
20
22
|
when :string then load_string(env_var, required)
|
21
23
|
when :int then load_int(env_var, required)
|
22
24
|
when :bool then load_bool(env_var, required)
|
25
|
+
when :date then load_date(env_var, required)
|
23
26
|
else raise ArgumentError, "Invalid type #{type}"
|
24
27
|
end
|
25
28
|
end
|
@@ -37,6 +40,7 @@ module Prius
|
|
37
40
|
@env.fetch(name)
|
38
41
|
rescue KeyError
|
39
42
|
return nil unless required
|
43
|
+
|
40
44
|
raise MissingValueError, "config value '#{name}' not present"
|
41
45
|
end
|
42
46
|
|
@@ -47,6 +51,7 @@ module Prius
|
|
47
51
|
unless value =~ /\A[0-9]+\z/
|
48
52
|
raise TypeMismatchError, "'#{name}' value '#{value}' is not an integer"
|
49
53
|
end
|
54
|
+
|
50
55
|
value.to_i
|
51
56
|
end
|
52
57
|
|
@@ -55,7 +60,17 @@ module Prius
|
|
55
60
|
return nil if value.nil?
|
56
61
|
return true if %w[yes y true t 1].include?(value)
|
57
62
|
return false if %w[no n false f 0].include?(value)
|
63
|
+
|
58
64
|
raise TypeMismatchError, "'#{name}' value '#{value}' is not a boolean"
|
59
65
|
end
|
66
|
+
|
67
|
+
def load_date(name, required)
|
68
|
+
value = load_string(name, required)
|
69
|
+
return nil if value.nil?
|
70
|
+
|
71
|
+
Date.parse(value)
|
72
|
+
rescue ArgumentError
|
73
|
+
raise TypeMismatchError, "'#{name}' value '#{value}' is not a date"
|
74
|
+
end
|
60
75
|
end
|
61
76
|
end
|
data/lib/prius/version.rb
CHANGED
data/lib/prius.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "prius/registry"
|
2
4
|
require "prius/railtie" if defined?(Rails)
|
3
5
|
|
@@ -12,7 +14,7 @@ module Prius
|
|
12
14
|
# omitted the uppercased form of `name` will be used.
|
13
15
|
# :type - The Symbol type of the environment variable's value.
|
14
16
|
# The value will be coerced to this type. Must be one
|
15
|
-
# of :string, :int, or :
|
17
|
+
# of :string, :int, :bool, or :date (default :string).
|
16
18
|
# :required - A Boolean indicating whether the value must be
|
17
19
|
# present in the environment. If true, a
|
18
20
|
# MissingValueError exception will be raised if the
|
data/prius.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'prius/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "prius"
|
8
8
|
spec.version = Prius::VERSION
|
9
|
-
spec.authors = ["
|
9
|
+
spec.authors = ["GoCardless Engineering"]
|
10
10
|
spec.email = ["engineering@gocardless.com"]
|
11
11
|
spec.description = %q{Environmentally-friendly config}
|
12
12
|
spec.summary = spec.description
|
@@ -18,6 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.required_ruby_version = ">= 2.6"
|
22
|
+
|
21
23
|
spec.add_development_dependency "rspec", "~> 3.1"
|
22
|
-
spec.add_development_dependency "rubocop", "~>
|
24
|
+
spec.add_development_dependency "rubocop", "~> 1.24"
|
25
|
+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.5.1"
|
26
|
+
spec.add_development_dependency "rubocop-performance", "~> 1.13"
|
23
27
|
end
|
data/spec/prius/registry_spec.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "prius/registry"
|
2
4
|
|
3
5
|
describe Prius::Registry do
|
4
|
-
let(:env)
|
6
|
+
let(:env) do
|
7
|
+
{
|
8
|
+
"NAME" => "Harry",
|
9
|
+
"AGE" => "25",
|
10
|
+
"ALIVE" => "yes",
|
11
|
+
"BORN" => "2022-09-02",
|
12
|
+
"INVALID_DATE" => "2022-02-99"
|
13
|
+
}
|
14
|
+
end
|
5
15
|
let(:registry) { Prius::Registry.new(env) }
|
6
16
|
|
7
17
|
describe "#load" do
|
@@ -70,6 +80,34 @@ describe Prius::Registry do
|
|
70
80
|
end
|
71
81
|
end
|
72
82
|
end
|
83
|
+
|
84
|
+
context "when specifying :date as the type" do
|
85
|
+
context "given a date value" do
|
86
|
+
it "doesn't blow up" do
|
87
|
+
expect { registry.load(:born, type: :date) }.to_not raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
it "stores a date" do
|
91
|
+
registry.load(:born, type: :date)
|
92
|
+
expect(registry.get(:born)).to be_a(Date)
|
93
|
+
expect(registry.get(:born)).to eq(Date.parse(env["BORN"]))
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "given an invalid date value" do
|
98
|
+
it "blows up" do
|
99
|
+
expect { registry.load(:invalid_date, type: :date) }.
|
100
|
+
to raise_error(Prius::TypeMismatchError)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "given a non-date value" do
|
105
|
+
it "blows up" do
|
106
|
+
expect { registry.load(:name, type: :date) }.
|
107
|
+
to raise_error(Prius::TypeMismatchError)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
73
111
|
end
|
74
112
|
|
75
113
|
describe "#get" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- GoCardless Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -30,14 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.24'
|
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: '1.24'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec_junit_formatter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.5.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.5.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop-performance
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
41
69
|
description: Environmentally-friendly config
|
42
70
|
email:
|
43
71
|
- engineering@gocardless.com
|
@@ -45,9 +73,10 @@ executables: []
|
|
45
73
|
extensions: []
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
76
|
+
- ".circleci/config.yml"
|
77
|
+
- ".github/dependabot.yml"
|
48
78
|
- ".gitignore"
|
49
79
|
- ".rubocop.yml"
|
50
|
-
- ".travis.yml"
|
51
80
|
- CHANGELOG.md
|
52
81
|
- Gemfile
|
53
82
|
- LICENSE
|
@@ -71,15 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
100
|
requirements:
|
72
101
|
- - ">="
|
73
102
|
- !ruby/object:Gem::Version
|
74
|
-
version: '
|
103
|
+
version: '2.6'
|
75
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
105
|
requirements:
|
77
106
|
- - ">="
|
78
107
|
- !ruby/object:Gem::Version
|
79
108
|
version: '0'
|
80
109
|
requirements: []
|
81
|
-
|
82
|
-
rubygems_version: 2.6.11
|
110
|
+
rubygems_version: 3.0.3.1
|
83
111
|
signing_key:
|
84
112
|
specification_version: 4
|
85
113
|
summary: Environmentally-friendly config
|