prius 4.1.0 → 6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4ec85e28d88e7ac3605c1f22d6a71c9d14ec4e25c67cce15fb0655b9e878ea0
4
- data.tar.gz: 81451517255e0cb04890cc93a1f39c4848e726019030cc45ccb11f07b7d934e0
3
+ metadata.gz: 8892ebc746ab5baf0ea2fee00e8bd3f7fc8f52494d8d2e9aec1e9d178e358333
4
+ data.tar.gz: d5443265d28678cb4f96fc5ec2fe3cea7afa3c3c7bb7a85f8d3155c1e61128a9
5
5
  SHA512:
6
- metadata.gz: 417aa19312808fac0140c6e052695268ea7291ea2dcec5aae6af3f5ee300e8cfdeb325380380a7b71ebec28b06b9ff127802f310d5e6b680287aaf83b0d49a43
7
- data.tar.gz: fdd5adfc03b58811922487ca08e94add9ee99abf19e0840775f58cb1ee93e315787723ce29cd38b99af49904eed2b96aa6cc388fcd6256b33872bbbff17ad9e0
6
+ metadata.gz: de66a2ae735c7cc8632085b01a47ddf3970cd68c928e60d82556305014770d3afc38e394beb72d0bb11d632ea270df97d7e259eb030a0a9eaf0c37c8c61e467d
7
+ data.tar.gz: 490b1e5e00a419cc500cd640fcc81af32d5b446f14a93f1cecbae0c33d3774d740a81068c1b622f50d92e1f2ec156090a0745f7430d9bbcfbc98db60aa1fa043
data/.rubocop.yml CHANGED
@@ -1,28 +1,33 @@
1
+ inherit_gem:
2
+ gc_ruboconfig: rubocop.yml
3
+
4
+ require:
5
+ - rubocop-rspec
6
+
1
7
  AllCops:
8
+ NewCops: enable
2
9
  Exclude:
3
- - prius.gemspec
4
10
  - vendor/**/*
5
- TargetRubyVersion: 2.6
6
-
7
- # Limit lines to 80 characters.
8
- LineLength:
9
- Max: 80
10
-
11
- ClassLength:
12
- Max: 300
13
-
14
- StringLiterals:
15
- Enabled: false
11
+ TargetRubyVersion: 3.1
16
12
 
17
13
  Style/Documentation:
18
14
  Enabled: false
19
15
 
20
16
  Style/SignalException:
21
- EnforcedStyle: 'only_raise'
17
+ EnforcedStyle: "only_raise"
22
18
 
23
19
  Layout/DotPosition:
24
- EnforcedStyle: 'trailing'
20
+ EnforcedStyle: "trailing"
25
21
 
26
22
  Metrics/BlockLength:
27
23
  Exclude:
28
24
  - "spec/**/*_spec.rb"
25
+
26
+ RSpec/NestedGroups:
27
+ Max: 5
28
+
29
+ Gemspec/RequiredRubyVersion:
30
+ Enabled: false
31
+
32
+ RSpec/MultipleExpectations:
33
+ Max: 5
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.0
data/CHANGELOG.md CHANGED
@@ -1,24 +1,34 @@
1
+ # 6.0.0 - 2024-01-09
2
+
3
+ - Drop support for Ruby 2.6 and 2.7.
4
+ - Add support for Ruby 3.2 and 3.3.
5
+ - Downcase boolean values when checking for truthiness.
6
+
7
+ # 5.0.0
8
+
9
+ - Ensure Prius#load raises an error when unexpected options are passed
10
+
1
11
  # 4.1.0
2
12
 
3
- * Add support for coercing to a date.
13
+ - Add support for coercing to a date.
4
14
 
5
15
  # 4.0.0
6
16
 
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)
17
+ - Add support for Ruby 3.0
18
+ - Enforce Ruby 2.6 as minimum required version
19
+ - Drop support for Ruby 2.2, 2.3, 2.4, 2.5
20
+ - Drop support for JRuby versions < 9.3.x (implicity enforced by C Ruby version 2.6 as minimum)
11
21
 
12
22
  # 3.0.0
13
23
 
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
24
+ - Enforce Ruby 2.2 as minimum required version
25
+ - Use CircleCI instead of Travis for CI builds
26
+ - Add Dependabot support
27
+ - Some development dependency updates
18
28
 
19
29
  # 2.0.0
20
30
 
21
- * Drop support for Ruby versions 1.9, 2.0, 2.1, and add support for 2.3 and 2.4
31
+ - Drop support for Ruby versions 1.9, 2.0, 2.1, and add support for 2.3 and 2.4
22
32
 
23
33
  # 1.0.0
24
34
 
data/Gemfile CHANGED
@@ -3,3 +3,10 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
+
7
+ group :development do
8
+ gem "gc_ruboconfig", "~> 4.4"
9
+ gem 'pry'
10
+ gem "rspec", "~> 3.12"
11
+ gem "rspec-github", "~> 2.4.0"
12
+ end
data/README.md CHANGED
@@ -48,7 +48,7 @@ Environment variables need to be loaded into the Prius registry before being
48
48
  used. Typically this is done in an initialiser.
49
49
 
50
50
  ```ruby
51
- Prius.load(name, options = {})
51
+ Prius.load(name, **options)
52
52
  ```
53
53
 
54
54
  If an environment variable can't be loaded, Prius will raise one of:
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "date"
3
4
  require "prius/errors"
4
5
 
5
6
  module Prius
@@ -14,10 +15,8 @@ module Prius
14
15
  end
15
16
 
16
17
  # See Prius.load for documentation.
17
- def load(name, options = {})
18
- env_var = options.fetch(:env_var, name.to_s.upcase)
19
- type = options.fetch(:type, :string)
20
- required = options.fetch(:required, true)
18
+ def load(name, env_var: nil, type: :string, required: true)
19
+ env_var = name.to_s.upcase if env_var.nil?
21
20
  @registry[name] = case type
22
21
  when :string then load_string(env_var, required)
23
22
  when :int then load_int(env_var, required)
@@ -48,7 +47,7 @@ module Prius
48
47
  value = load_string(name, required)
49
48
  return value if value.nil?
50
49
 
51
- unless value =~ /\A[0-9]+\z/
50
+ unless /\A[0-9]+\z/.match?(value)
52
51
  raise TypeMismatchError, "'#{name}' value '#{value}' is not an integer"
53
52
  end
54
53
 
@@ -58,6 +57,8 @@ module Prius
58
57
  def load_bool(name, required)
59
58
  value = load_string(name, required)
60
59
  return nil if value.nil?
60
+
61
+ value = value.downcase
61
62
  return true if %w[yes y true t 1].include?(value)
62
63
  return false if %w[no n false f 0].include?(value)
63
64
 
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.1.0"
4
+ VERSION = "6.0.0"
5
5
  end
data/lib/prius.rb CHANGED
@@ -25,8 +25,8 @@ module Prius
25
25
  # Raises a MissingValueError for required values that are missing.
26
26
  # Raises a TypeMismatchError if a value can't be coerced to the given `type`.
27
27
  # Raises an ArgumentError if an invalid `type` is provided.
28
- def self.load(name, options = {})
29
- registry.load(name, options)
28
+ def self.load(name, **options)
29
+ registry.load(name, **options)
30
30
  end
31
31
 
32
32
  # Fetch a value from the registry.
data/prius.gemspec CHANGED
@@ -1,27 +1,30 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'prius/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/prius/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "prius"
8
7
  spec.version = Prius::VERSION
9
8
  spec.authors = ["GoCardless Engineering"]
10
9
  spec.email = ["engineering@gocardless.com"]
11
- spec.description = %q{Environmentally-friendly config}
12
- spec.summary = spec.description
10
+ spec.summary = "Environmentally-friendly config. Validate and enforce the presence " \
11
+ "and correct types of environment variables."
12
+ spec.description = <<~MSG.strip.tr("\n", " ")
13
+ Prius is a powerful and versatile gem designed to simplify the management of environment variables
14
+ in your application. With Prius, you can guarantee that your environment variables are not only
15
+ present but also valid, ensuring a smoother and more reliable app experience.
16
+ MSG
13
17
  spec.homepage = "https://github.com/gocardless/prius"
14
18
  spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
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"
21
+ spec.required_ruby_version = ">= 3.0"
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/
25
+ .git .circleci appveyor])
26
+ end
27
+ end
22
28
 
23
- spec.add_development_dependency "rspec", "~> 3.1"
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"
29
+ spec.metadata["rubygems_mfa_required"] = "true"
27
30
  end
metadata CHANGED
@@ -1,82 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prius
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 6.0.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-09-05 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rspec
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '3.1'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.1'
27
- - !ruby/object:Gem::Dependency
28
- name: rubocop
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.24'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::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'
69
- description: Environmentally-friendly config
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Prius is a powerful and versatile gem designed to simplify the management
14
+ of environment variables in your application. With Prius, you can guarantee that
15
+ your environment variables are not only present but also valid, ensuring a smoother
16
+ and more reliable app experience.
70
17
  email:
71
18
  - engineering@gocardless.com
72
19
  executables: []
73
20
  extensions: []
74
21
  extra_rdoc_files: []
75
22
  files:
76
- - ".circleci/config.yml"
77
- - ".github/dependabot.yml"
78
- - ".gitignore"
79
23
  - ".rubocop.yml"
24
+ - ".ruby-version"
80
25
  - CHANGELOG.md
81
26
  - Gemfile
82
27
  - LICENSE
@@ -87,12 +32,12 @@ files:
87
32
  - lib/prius/registry.rb
88
33
  - lib/prius/version.rb
89
34
  - prius.gemspec
90
- - spec/prius/registry_spec.rb
91
35
  homepage: https://github.com/gocardless/prius
92
36
  licenses:
93
37
  - MIT
94
- metadata: {}
95
- post_install_message:
38
+ metadata:
39
+ rubygems_mfa_required: 'true'
40
+ post_install_message:
96
41
  rdoc_options: []
97
42
  require_paths:
98
43
  - lib
@@ -100,16 +45,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
45
  requirements:
101
46
  - - ">="
102
47
  - !ruby/object:Gem::Version
103
- version: '2.6'
48
+ version: '3.0'
104
49
  required_rubygems_version: !ruby/object:Gem::Requirement
105
50
  requirements:
106
51
  - - ">="
107
52
  - !ruby/object:Gem::Version
108
53
  version: '0'
109
54
  requirements: []
110
- rubygems_version: 3.0.3.1
111
- signing_key:
55
+ rubygems_version: 3.5.3
56
+ signing_key:
112
57
  specification_version: 4
113
- summary: Environmentally-friendly config
114
- test_files:
115
- - spec/prius/registry_spec.rb
58
+ summary: Environmentally-friendly config. Validate and enforce the presence and correct
59
+ types of environment variables.
60
+ test_files: []
data/.circleci/config.yml DELETED
@@ -1,60 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: "/"
5
- schedule:
6
- interval: weekly
7
- open-pull-requests-limit: 10
data/.gitignore DELETED
@@ -1,3 +0,0 @@
1
- Gemfile.lock
2
- .bundle
3
- *.gem
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "prius/registry"
4
-
5
- describe Prius::Registry do
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
15
- let(:registry) { Prius::Registry.new(env) }
16
-
17
- describe "#load" do
18
- context "given a name that's present in the environment" do
19
- it "doesn't blow up" do
20
- expect { registry.load(:name) }.to_not raise_error
21
- end
22
- end
23
-
24
- context "given a name that's not present in the environment" do
25
- it "blows up" do
26
- expect { registry.load(:slogan) }.
27
- to raise_error(Prius::MissingValueError)
28
- end
29
-
30
- context "when required is false" do
31
- it "doesn't blow up" do
32
- expect { registry.load(:slogan, required: false) }.to_not raise_error
33
- end
34
- end
35
- end
36
-
37
- context "given an invalid type" do
38
- it "blows up" do
39
- expect { registry.load(:name, type: :lightsabre) }.
40
- to raise_error(ArgumentError)
41
- end
42
- end
43
-
44
- context "when specifying :int as the type" do
45
- context "given a integer value" do
46
- it "doesn't blow up" do
47
- expect { registry.load(:age, type: :int) }.to_not raise_error
48
- end
49
-
50
- it "stores an int" do
51
- registry.load(:age, type: :int)
52
- expect(registry.get(:age)).to be_a(Integer)
53
- end
54
- end
55
-
56
- context "given a non-integer value" do
57
- it "blows up" do
58
- expect { registry.load(:name, type: :int) }.
59
- to raise_error(Prius::TypeMismatchError)
60
- end
61
- end
62
- end
63
-
64
- context "when specifying :bool as the type" do
65
- context "given a boolean value" do
66
- it "doesn't blow up" do
67
- expect { registry.load(:alive, type: :bool) }.to_not raise_error
68
- end
69
-
70
- it "stores an boolean" do
71
- registry.load(:alive, type: :bool)
72
- expect(registry.get(:alive)).to be_a(TrueClass)
73
- end
74
- end
75
-
76
- context "given a non-boolean value" do
77
- it "blows up" do
78
- expect { registry.load(:name, type: :bool) }.
79
- to raise_error(Prius::TypeMismatchError)
80
- end
81
- end
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
111
- end
112
-
113
- describe "#get" do
114
- context "given a name that has been loaded" do
115
- before { registry.load(:name) }
116
- it "returns the value" do
117
- expect(registry.get(:name)).to eq("Harry")
118
- end
119
- end
120
-
121
- context "given a name that hasn't been loaded" do
122
- it "blows up" do
123
- expect { registry.get(:name) }.
124
- to raise_error(Prius::UndeclaredNameError)
125
- end
126
- end
127
-
128
- context "given a nillable name that has been loaded" do
129
- before { registry.load(:lightsabre, required: false) }
130
- it "returns nil" do
131
- expect(registry.get(:lightsabre)).to be_nil
132
- end
133
- end
134
- end
135
- end