dotenv 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -4
- data/lib/dotenv.rb +3 -3
- data/lib/dotenv/environment.rb +4 -4
- data/lib/dotenv/parser.rb +16 -17
- data/lib/dotenv/substitutions/command.rb +1 -1
- data/lib/dotenv/substitutions/variable.rb +18 -8
- data/lib/dotenv/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd76e5c6ca084e248496b42e52b9108a0107e2d
|
4
|
+
data.tar.gz: d59561a4c5ece858dc36bf61194b8eda14064770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2fa80964b37fb1dfefb578945b93f0b2bac3476ddfb8429ab72835db67bec5d8c197ec27949a84769bca3895fd9c51916a1bc78eb864d76ce172634ffff7b5
|
7
|
+
data.tar.gz: f8caadc5aec3fef268b085a99cc032d7e102deb2121239fe2cb5d721414a71d1b428de288d15b8cb51989559b9fac96de245489ba9f1f27c94a5534d8ecae78f
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv)
|
2
|
-
|
3
|
-
[![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.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)
|
4
2
|
|
5
3
|
Shim to load environment variables from `.env` into `ENV` in *development*.
|
6
4
|
|
@@ -75,6 +73,12 @@ Alternatively, you can use the `dotenv` executable to launch your application:
|
|
75
73
|
$ dotenv ./script.rb
|
76
74
|
```
|
77
75
|
|
76
|
+
The `dotenv` executable also accepts a single flag, `-f`. Its value should be a comma-separated list of configuration files, in the order of most important to least. All of the files must exist. There _must_ be a space between the flag and its value.
|
77
|
+
|
78
|
+
```
|
79
|
+
$ dotenv -f ".env.local,.env" ./script.rb
|
80
|
+
```
|
81
|
+
|
78
82
|
To ensure `.env` is loaded in rake, load the tasks:
|
79
83
|
|
80
84
|
```ruby
|
@@ -112,9 +116,21 @@ export SECRET_KEY=YOURSECRETKEYGOESHERE
|
|
112
116
|
If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
|
113
117
|
|
114
118
|
```shell
|
115
|
-
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9
|
119
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9...\n-----END DSA PRIVATE KEY-----\n"
|
116
120
|
```
|
117
121
|
|
122
|
+
Alternatively, multi-line values with line breaks are now supported for quoted values.
|
123
|
+
|
124
|
+
```shell
|
125
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
|
126
|
+
...
|
127
|
+
HkVN9...
|
128
|
+
...
|
129
|
+
-----END DSA PRIVATE KEY-----"
|
130
|
+
```
|
131
|
+
|
132
|
+
This is particularly helpful when using the Heroku command line plugin [`heroku-config`](https://github.com/xavdid/heroku-config) to pull configuration variables down that may have line breaks.
|
133
|
+
|
118
134
|
### Command Substitution
|
119
135
|
|
120
136
|
You need to add the output of a command in one of your variables? Simply add it with `$(your_command)`:
|
data/lib/dotenv.rb
CHANGED
@@ -12,7 +12,7 @@ module Dotenv
|
|
12
12
|
def load(*filenames)
|
13
13
|
with(*filenames) do |f|
|
14
14
|
ignoring_nonexistent_files do
|
15
|
-
env = Environment.new(f)
|
15
|
+
env = Environment.new(f, true)
|
16
16
|
instrument("dotenv.load", env: env) { env.apply }
|
17
17
|
end
|
18
18
|
end
|
@@ -21,7 +21,7 @@ module Dotenv
|
|
21
21
|
# same as `load`, but raises Errno::ENOENT if any files don't exist
|
22
22
|
def load!(*filenames)
|
23
23
|
with(*filenames) do |f|
|
24
|
-
env = Environment.new(f)
|
24
|
+
env = Environment.new(f, true)
|
25
25
|
instrument("dotenv.load", env: env) { env.apply }
|
26
26
|
end
|
27
27
|
end
|
@@ -30,7 +30,7 @@ module Dotenv
|
|
30
30
|
def overload(*filenames)
|
31
31
|
with(*filenames) do |f|
|
32
32
|
ignoring_nonexistent_files do
|
33
|
-
env = Environment.new(f)
|
33
|
+
env = Environment.new(f, false)
|
34
34
|
instrument("dotenv.overload", env: env) { env.apply! }
|
35
35
|
end
|
36
36
|
end
|
data/lib/dotenv/environment.rb
CHANGED
@@ -4,13 +4,13 @@ module Dotenv
|
|
4
4
|
class Environment < Hash
|
5
5
|
attr_reader :filename
|
6
6
|
|
7
|
-
def initialize(filename)
|
7
|
+
def initialize(filename, is_load)
|
8
8
|
@filename = filename
|
9
|
-
load
|
9
|
+
load(is_load)
|
10
10
|
end
|
11
11
|
|
12
|
-
def load
|
13
|
-
update Parser.call(read)
|
12
|
+
def load(is_load)
|
13
|
+
update Parser.call(read, is_load)
|
14
14
|
end
|
15
15
|
|
16
16
|
def read
|
data/lib/dotenv/parser.rb
CHANGED
@@ -12,38 +12,42 @@ module Dotenv
|
|
12
12
|
[Dotenv::Substitutions::Variable, Dotenv::Substitutions::Command]
|
13
13
|
|
14
14
|
LINE = /
|
15
|
-
\A
|
16
15
|
\s*
|
17
16
|
(?:export\s+)? # optional export
|
18
17
|
([\w\.]+) # key
|
19
18
|
(?:\s*=\s*|:\s+?) # separator
|
20
19
|
( # optional value begin
|
21
|
-
'(
|
20
|
+
'(?:\\'|[^'])*' # single quoted value
|
22
21
|
| # or
|
23
|
-
"(
|
22
|
+
"(?:\\"|[^"])*" # double quoted value
|
24
23
|
| # or
|
25
|
-
[^#\n]+ # unquoted value
|
24
|
+
[^#\r\n]+ # unquoted value
|
26
25
|
)? # value end
|
27
26
|
\s*
|
28
27
|
(?:\#.*)? # optional comment
|
29
|
-
\z
|
30
28
|
/x
|
31
29
|
|
32
30
|
class << self
|
33
31
|
attr_reader :substitutions
|
34
32
|
|
35
|
-
def call(string)
|
36
|
-
new(string).call
|
33
|
+
def call(string, is_load)
|
34
|
+
new(string, is_load).call
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
def initialize(string)
|
38
|
+
def initialize(string, is_load)
|
41
39
|
@string = string
|
42
40
|
@hash = {}
|
41
|
+
@is_load = is_load
|
43
42
|
end
|
44
43
|
|
45
44
|
def call
|
46
|
-
|
45
|
+
# Process matches
|
46
|
+
@string.scan(LINE).each do |key, value|
|
47
|
+
@hash[key] = parse_value(value || "")
|
48
|
+
end
|
49
|
+
# Process non-matches
|
50
|
+
@string.gsub(LINE, "").split(/[\n\r]+/).each do |line|
|
47
51
|
parse_line(line)
|
48
52
|
end
|
49
53
|
@hash
|
@@ -52,21 +56,16 @@ module Dotenv
|
|
52
56
|
private
|
53
57
|
|
54
58
|
def parse_line(line)
|
55
|
-
if
|
56
|
-
key, value = match.captures
|
57
|
-
@hash[key] = parse_value(value || "")
|
58
|
-
elsif line.split.first == "export"
|
59
|
+
if line.split.first == "export"
|
59
60
|
if variable_not_set?(line)
|
60
61
|
raise FormatError, "Line #{line.inspect} has an unset variable"
|
61
62
|
end
|
62
|
-
elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line
|
63
|
-
raise FormatError, "Line #{line.inspect} doesn't match format"
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
67
66
|
def parse_value(value)
|
68
67
|
# Remove surrounding quotes
|
69
|
-
value = value.strip.sub(/\A(['"])(.*)\1\z
|
68
|
+
value = value.strip.sub(/\A(['"])(.*)\1\z/m, '\2')
|
70
69
|
|
71
70
|
if Regexp.last_match(1) == '"'
|
72
71
|
value = unescape_characters(expand_newlines(value))
|
@@ -74,7 +73,7 @@ module Dotenv
|
|
74
73
|
|
75
74
|
if Regexp.last_match(1) != "'"
|
76
75
|
self.class.substitutions.each do |proc|
|
77
|
-
value = proc.call(value, @hash)
|
76
|
+
value = proc.call(value, @hash, @is_load)
|
78
77
|
end
|
79
78
|
end
|
80
79
|
value
|
@@ -18,17 +18,27 @@ module Dotenv
|
|
18
18
|
\}? # closing brace
|
19
19
|
/xi
|
20
20
|
|
21
|
-
def call(value, env)
|
21
|
+
def call(value, env, is_load)
|
22
|
+
combined_env = if is_load
|
23
|
+
env.merge(ENV)
|
24
|
+
else
|
25
|
+
ENV.to_h.merge(env)
|
26
|
+
end
|
22
27
|
value.gsub(VARIABLE) do |variable|
|
23
28
|
match = $LAST_MATCH_INFO
|
29
|
+
substitute(match, variable, combined_env)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
def substitute(match, variable, env)
|
36
|
+
if match[1] == '\\'
|
37
|
+
variable[1..-1]
|
38
|
+
elsif match[3]
|
39
|
+
env.fetch(match[3], "")
|
40
|
+
else
|
41
|
+
variable
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
data/lib/dotenv/version.rb
CHANGED
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.
|
4
|
+
version: 2.3.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-04-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
95
|
+
rubygems_version: 2.6.11
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Loads environment variables from `.env`.
|