dotenv 2.5.0 → 2.7.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
- SHA1:
3
- metadata.gz: 2e64cd0a67971ea4a843e624a6362e89b623697c
4
- data.tar.gz: 7dd0bbd8488f581d5dbf1f4bfcdc5c3e97bdf623
2
+ SHA256:
3
+ metadata.gz: fadc1aaf858a18707131513d5fa3dc015a6c6cd52f6402a92a873ea8b9bb1cda
4
+ data.tar.gz: c07851bf8fa4dcd429420a416f099a1202e2790937413d96d1861a7e1580056e
5
5
  SHA512:
6
- metadata.gz: e7e8fcbb2f35999a5e3ccf1d6f37b97aa6d21ddffbb59235cad590b15d1e9e74356da50174393de20cde97395046fe4f48edf8a5aec59d5901117c21cb94f953
7
- data.tar.gz: fed27a558c70aa6d7b0f435f16b437c0be83a60c1525c6afe89add406e68ec94c3ebdffbc6698c3ae8952ce1cab576c2bab683e11e68ca2f40c5d16778ab2c97
6
+ metadata.gz: 3815788d3a7f2527dc89c57e15c67cf10bcdf7dd6d12ddb2f4c5eadc5be3c98ab55fd90077a2df829b431b4ce36c04e1e7a3f484f728f7fd498df85d41cc1c73
7
+ data.tar.gz: 15788c3ecc0ab48db28ff231d4a2bc4a79c8d52786dd0994b5c3839aa709bd58b541205f8683d0dd4ad7101f6d3ca604f590814979165d0adffcce7b8fd5be13
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1
+ # dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.svg?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
2
 
3
3
  Shim to load environment variables from `.env` into `ENV` in *development*.
4
4
 
@@ -163,6 +163,31 @@ SECRET_KEY=YOURSECRETKEYGOESHERE # comment
163
163
  SECRET_HASH="something-with-a-#-hash"
164
164
  ```
165
165
 
166
+ ### Required Keys
167
+
168
+ If a particular configuration value is required but not set, it's appropriate to raise an error.
169
+
170
+ To require configuration keys:
171
+
172
+ ```ruby
173
+ # config/initializers/dotenv.rb
174
+
175
+ Dotenv.require_keys("SERVICE_APP_ID", "SERVICE_KEY", "SERVICE_SECRET")
176
+ ```
177
+
178
+ If any of the configuration keys above are not set, your application will raise an error during initialization. This method is preferred because it prevents runtime errors in a production application due to improper configuration.
179
+
180
+ ### Parsing
181
+
182
+ To parse a list of env files for programmatic inspection without modifying the ENV:
183
+
184
+ ```ruby
185
+ Dotenv.parse(".env.local", ".env")
186
+ # => {'S3_BUCKET' => 'YOURS3BUCKET', 'SECRET_KEY' => 'YOURSECRETKEYGOESHERE', ...}
187
+ ```
188
+
189
+ This method returns a hash of the ENV var name/value pairs.
190
+
166
191
  ## Frequently Answered Questions
167
192
 
168
193
  ### Can I use dotenv in production?
@@ -175,12 +200,19 @@ If you use this gem to handle env vars for multiple Rails environments (developm
175
200
 
176
201
  ### What other .env* files can I use?
177
202
 
178
- `dotenv-rails` will load the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence:
203
+ `dotenv-rails` will override in the following order (highest defined variable overrides lower):
204
+
205
+ | Hierarchy Priority | Filename | Environment | Should I `.gitignore`it? | Notes |
206
+ | ------------------ | ------------------------ | -------------------- | --------------------------------------------------- | ------------------------------------------------------------ |
207
+ | 1st (highest) | `.env.development.local` | Development | Yes! | Local overrides of environment-specific settings. |
208
+ | 1st | `.env.test.local` | Test | Yes! | Local overrides of environment-specific settings. |
209
+ | 1st | `.env.production.local` | Production | Yes! | Local overrides of environment-specific settings. |
210
+ | 2nd | `.env.local` | Wherever the file is | Definitely. | Local overrides. This file is loaded for all environments _except_ `test`. |
211
+ | 3rd | `.env.development` | Development | No. | Shared environment-specific settings |
212
+ | 3rd | `.env.test` | Test | No. | Shared environment-specific settings |
213
+ | 3rd | `.env.production` | Production | No. | Shared environment-specific settings |
214
+ | Last | `.env` | All Environments | Depends (See [below](#should-i-commit-my-env-file)) | The Original® |
179
215
 
180
- - `.env` - The Original®
181
- - `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
182
- - `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`.
183
- - `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.
184
216
 
185
217
  ### Should I commit my .env file?
186
218
 
data/lib/dotenv.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "dotenv/parser"
2
2
  require "dotenv/environment"
3
+ require "dotenv/missing_keys"
3
4
 
4
5
  # The top level Dotenv module. The entrypoint for the application logic.
5
6
  module Dotenv
@@ -36,6 +37,23 @@ module Dotenv
36
37
  end
37
38
  end
38
39
 
40
+ # same as `overload`, but raises Errno::ENOENT if any files don't exist
41
+ def overload!(*filenames)
42
+ with(*filenames) do |f|
43
+ env = Environment.new(f, false)
44
+ instrument("dotenv.overload", env: env) { env.apply! }
45
+ end
46
+ end
47
+
48
+ # returns a hash of parsed key/value pairs but does not modify ENV
49
+ def parse(*filenames)
50
+ with(*filenames) do |f|
51
+ ignoring_nonexistent_files do
52
+ Environment.new(f, false)
53
+ end
54
+ end
55
+ end
56
+
39
57
  # Internal: Helper to expand list of filenames.
40
58
  #
41
59
  # Returns a hash of all the loaded environment variables.
@@ -55,6 +73,12 @@ module Dotenv
55
73
  end
56
74
  end
57
75
 
76
+ def require_keys(*keys)
77
+ missing_keys = keys.flatten - ::ENV.keys
78
+ return if missing_keys.empty?
79
+ raise MissingKeys, missing_keys
80
+ end
81
+
58
82
  def ignoring_nonexistent_files
59
83
  yield
60
84
  rescue Errno::ENOENT
data/lib/dotenv/cli.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "dotenv"
2
+ require "dotenv/version"
3
+ require "optparse"
2
4
 
3
5
  module Dotenv
4
6
  # The CLI is a class responsible of handling all the command line interface
@@ -11,26 +13,55 @@ module Dotenv
11
13
  end
12
14
 
13
15
  def run
14
- filenames = parse_filenames || []
16
+ parse_argv!(@argv)
17
+
15
18
  begin
16
- Dotenv.load!(*filenames)
19
+ Dotenv.load!(*@filenames)
17
20
  rescue Errno::ENOENT => e
18
21
  abort e.message
19
22
  else
20
- exec(*argv) unless argv.empty?
23
+ exec(*@argv) unless @argv.empty?
21
24
  end
22
25
  end
23
26
 
24
27
  private
25
28
 
26
- def parse_filenames
27
- pos = argv.index("-f")
28
- return nil unless pos
29
- # drop the -f
30
- argv.delete_at pos
31
- # parse one or more comma-separated .env files
32
- require "csv"
33
- CSV.parse_line argv.delete_at(pos)
29
+ def parse_argv!(argv)
30
+ @filenames = []
31
+
32
+ OptionParser.new do |parser|
33
+ parser.banner = "Usage: dotenv [options]"
34
+ parser.separator ""
35
+ add_options(parser)
36
+ end.parse!(argv)
37
+
38
+ @filenames
39
+ end
40
+
41
+ def add_options(parser)
42
+ add_files_option(parser)
43
+ add_help_option(parser)
44
+ add_version_option(parser)
45
+ end
46
+
47
+ def add_files_option(parser)
48
+ parser.on("-f FILES", Array, "List of env files to parse") do |list|
49
+ @filenames = list
50
+ end
51
+ end
52
+
53
+ def add_help_option(parser)
54
+ parser.on("-h", "--help", "Display help") do
55
+ puts parser
56
+ exit
57
+ end
58
+ end
59
+
60
+ def add_version_option(parser)
61
+ parser.on("-v", "--version", "Show version") do
62
+ puts "dotenv #{Dotenv::VERSION}"
63
+ exit
64
+ end
34
65
  end
35
66
  end
36
67
  end
@@ -0,0 +1,10 @@
1
+ module Dotenv
2
+ class Error < StandardError; end
3
+
4
+ class MissingKeys < Error # :nodoc:
5
+ def initialize(keys)
6
+ key_word = "key#{keys.size > 1 ? 's' : ''}"
7
+ super("Missing required configuration #{key_word}: #{keys.inspect}")
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "2.5.0".freeze
2
+ VERSION = "2.7.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2019-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -67,6 +67,7 @@ files:
67
67
  - lib/dotenv/cli.rb
68
68
  - lib/dotenv/environment.rb
69
69
  - lib/dotenv/load.rb
70
+ - lib/dotenv/missing_keys.rb
70
71
  - lib/dotenv/parser.rb
71
72
  - lib/dotenv/substitutions/command.rb
72
73
  - lib/dotenv/substitutions/variable.rb
@@ -91,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
92
  - !ruby/object:Gem::Version
92
93
  version: '0'
93
94
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.13
95
+ rubygems_version: 3.0.1
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Loads environment variables from `.env`.