prius 4.0.0 → 4.1.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 +4 -4
 - data/CHANGELOG.md +4 -0
 - data/README.md +2 -2
 - data/lib/prius/registry.rb +10 -0
 - data/lib/prius/version.rb +1 -1
 - data/lib/prius.rb +1 -1
 - data/spec/prius/registry_spec.rb +37 -1
 - metadata +6 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 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
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        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  
     | 
| 
      
 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/registry.rb
    CHANGED
    
    | 
         @@ -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
    
    
    
        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 : 
     | 
| 
      
 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
         
     | 
    
        data/spec/prius/registry_spec.rb
    CHANGED
    
    | 
         @@ -3,7 +3,15 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require "prius/registry"
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            describe Prius::Registry do
         
     | 
| 
       6 
     | 
    
         
            -
              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
         
     | 
| 
       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. 
     | 
| 
      
 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- 
     | 
| 
      
 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. 
     | 
| 
       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:
         
     |