prius 4.0.0 → 4.1.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
  SHA256:
3
- metadata.gz: a2e2b95c7456b01442cf90ba9ad16d4a4ca872bbcf765f15aefeb0b5ff132003
4
- data.tar.gz: 1f3cf76e9746fc2433d297e0090a1f4ab166ceda25de176ccee0826e02b99c50
3
+ metadata.gz: a4ec85e28d88e7ac3605c1f22d6a71c9d14ec4e25c67cce15fb0655b9e878ea0
4
+ data.tar.gz: 81451517255e0cb04890cc93a1f39c4848e726019030cc45ccb11f07b7d934e0
5
5
  SHA512:
6
- metadata.gz: cb70cd3bc19f29b24ed2a980d713a45476a8ff1006f853b6dbc8ab2091f743208d819eaffdf098234114c847420729bf7c7d119c8726f8ca8a02fabc0c95c68f
7
- data.tar.gz: 53df6a3b348e74b69c193a36ad56b3d5e4c5dc0360347eadd7f570a06b820ebdef8344d921467d7cd6e5221f61499d8890fa7bea5264e1b563a6d760397210f4
6
+ metadata.gz: 417aa19312808fac0140c6e052695268ea7291ea2dcec5aae6af3f5ee300e8cfdeb325380380a7b71ebec28b06b9ff127802f310d5e6b680287aaf83b0d49a43
7
+ data.tar.gz: fdd5adfc03b58811922487ca08e94add9ee99abf19e0840775f58cb1ee93e315787723ce29cd38b99af49904eed2b96aa6cc388fcd6256b33872bbbff17ad9e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 4.1.0
2
+
3
+ * Add support for coercing to a date.
4
+
1
5
  # 4.0.0
2
6
 
3
7
  * Add support for Ruby 3.0
data/README.md CHANGED
@@ -9,7 +9,7 @@ Prius helps you guarantee that your environment variables are:
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 string), and an exception will be raised if the value
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` and `:bool`. |
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
@@ -22,6 +22,7 @@ module Prius
22
22
  when :string then load_string(env_var, required)
23
23
  when :int then load_int(env_var, required)
24
24
  when :bool then load_bool(env_var, required)
25
+ when :date then load_date(env_var, required)
25
26
  else raise ArgumentError, "Invalid type #{type}"
26
27
  end
27
28
  end
@@ -62,5 +63,14 @@ module Prius
62
63
 
63
64
  raise TypeMismatchError, "'#{name}' value '#{value}' is not a boolean"
64
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
65
75
  end
66
76
  end
data/lib/prius/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Prius
4
- VERSION = "4.0.0"
4
+ VERSION = "4.1.0"
5
5
  end
data/lib/prius.rb CHANGED
@@ -14,7 +14,7 @@ module Prius
14
14
  # omitted the uppercased form of `name` will be used.
15
15
  # :type - The Symbol type of the environment variable's value.
16
16
  # The value will be coerced to this type. Must be one
17
- # of :string, :int, or :bool (default :string).
17
+ # of :string, :int, :bool, or :date (default :string).
18
18
  # :required - A Boolean indicating whether the value must be
19
19
  # present in the environment. If true, a
20
20
  # MissingValueError exception will be raised if the
@@ -3,7 +3,15 @@
3
3
  require "prius/registry"
4
4
 
5
5
  describe Prius::Registry do
6
- let(:env) { { "NAME" => "Harry", "AGE" => "25", "ALIVE" => "yes" } }
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
7
15
  let(:registry) { Prius::Registry.new(env) }
8
16
 
9
17
  describe "#load" do
@@ -72,6 +80,34 @@ describe Prius::Registry do
72
80
  end
73
81
  end
74
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
75
111
  end
76
112
 
77
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.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -92,7 +92,7 @@ homepage: https://github.com/gocardless/prius
92
92
  licenses:
93
93
  - MIT
94
94
  metadata: {}
95
- post_install_message:
95
+ post_install_message:
96
96
  rdoc_options: []
97
97
  require_paths:
98
98
  - lib
@@ -107,8 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.2.15
111
- signing_key:
110
+ rubygems_version: 3.0.3.1
111
+ signing_key:
112
112
  specification_version: 4
113
113
  summary: Environmentally-friendly config
114
114
  test_files: