dotenv 3.1.0 → 3.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/dotenv/diff.rb +4 -1
- data/lib/dotenv/rails.rb +3 -6
- data/lib/dotenv/template.rb +24 -6
- data/lib/dotenv/version.rb +1 -1
- data/lib/dotenv.rb +4 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbefe05cecd5a12cdd9a9dc72b3ff2feee883c10f84c40c9105d3d9c1c5ffc3c
|
4
|
+
data.tar.gz: a61066d9119426fa542acf6a17d7134033d17cef8bdf71fe87e964a5d4b5e925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9941e0374f811e9048db77c77731106b1b3f75eff0358d6c2a8ef24265857ccfb02d76409f733f1f930815f4b032e5939520ee6c0a48d3eaa00d734be036eb4b
|
7
|
+
data.tar.gz: 83b856b11c9817f51151e4249a1fb5fd38b057720a049270ffa7fcf05a20547ce2db29e6690feb8f536478b0995549eaa52a90b5d1a019af5aa73ce6def3e561
|
data/README.md
CHANGED
@@ -180,7 +180,7 @@ end
|
|
180
180
|
Available options:
|
181
181
|
|
182
182
|
* `Dotenv::Rails.files` - list of files to be loaded, in order of precedence.
|
183
|
-
* `Dotenv::Rails.overwrite` - Overwrite
|
183
|
+
* `Dotenv::Rails.overwrite` - Overwrite existing `ENV` variables with contents of `.env*` files
|
184
184
|
* `Dotenv::Rails.logger` - The logger to use for dotenv's logging. Defaults to `Rails.logger`
|
185
185
|
* `Dotenv::Rails.autorestore` - Enable or disable [autorestore](#autorestore-in-tests)
|
186
186
|
|
@@ -276,7 +276,7 @@ You can use the `-t` or `--template` flag on the dotenv cli to create a template
|
|
276
276
|
```console
|
277
277
|
$ dotenv -t .env
|
278
278
|
```
|
279
|
-
A template will be created in your working directory named `{
|
279
|
+
A template will be created in your working directory named `{FILENAME}.template`. So in the above example, it would create a `.env.template` file.
|
280
280
|
|
281
281
|
The template will contain all the environment variables in your `.env` file but with their values set to the variable names.
|
282
282
|
|
data/lib/dotenv/diff.rb
CHANGED
@@ -50,7 +50,10 @@ module Dotenv
|
|
50
50
|
private
|
51
51
|
|
52
52
|
def snapshot
|
53
|
-
ENV
|
53
|
+
# `dup` should not be required here, but some people use `stub_const` to replace ENV with
|
54
|
+
# a `Hash`. This ensures that we get a frozen copy of that instead of freezing the original.
|
55
|
+
# https://github.com/bkeepers/dotenv/issues/482
|
56
|
+
ENV.to_h.dup.freeze
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
data/lib/dotenv/rails.rb
CHANGED
@@ -10,14 +10,11 @@ require "dotenv/log_subscriber"
|
|
10
10
|
Dotenv.instrumenter = ActiveSupport::Notifications
|
11
11
|
|
12
12
|
# Watch all loaded env files with Spring
|
13
|
-
|
14
|
-
|
15
|
-
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
|
13
|
+
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
|
14
|
+
if defined?(Spring) && Spring.respond_to?(:watch)
|
16
15
|
event = ActiveSupport::Notifications::Event.new(*args)
|
17
16
|
Spring.watch event.payload[:env].filename if Rails.application
|
18
17
|
end
|
19
|
-
rescue LoadError, ArgumentError
|
20
|
-
# Spring is not available
|
21
18
|
end
|
22
19
|
|
23
20
|
module Dotenv
|
@@ -26,7 +23,7 @@ module Dotenv
|
|
26
23
|
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, to: "config.dotenv"
|
27
24
|
|
28
25
|
def initialize
|
29
|
-
super
|
26
|
+
super
|
30
27
|
config.dotenv = ActiveSupport::OrderedOptions.new.update(
|
31
28
|
# Rails.logger is not available yet, so we'll save log messages and replay them when it is
|
32
29
|
logger: Dotenv::ReplayLogger.new,
|
data/lib/dotenv/template.rb
CHANGED
@@ -10,17 +10,35 @@ module Dotenv
|
|
10
10
|
File.open(@env_file, "r") do |env_file|
|
11
11
|
File.open("#{@env_file}.template", "w") do |env_template|
|
12
12
|
env_file.each do |line|
|
13
|
-
|
13
|
+
if is_comment?(line)
|
14
|
+
env_template.puts line
|
15
|
+
elsif (var = var_defined?(line))
|
16
|
+
if line.match(EXPORT_COMMAND)
|
17
|
+
env_template.puts "export #{var}=#{var}"
|
18
|
+
else
|
19
|
+
env_template.puts "#{var}=#{var}"
|
20
|
+
end
|
21
|
+
elsif line_blank?(line)
|
22
|
+
env_template.puts
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
def is_comment?(line)
|
32
|
+
line.strip.start_with?("#")
|
33
|
+
end
|
34
|
+
|
35
|
+
def var_defined?(line)
|
36
|
+
match = Dotenv::Parser::LINE.match(line)
|
37
|
+
match && match[1]
|
38
|
+
end
|
39
|
+
|
40
|
+
def line_blank?(line)
|
41
|
+
line.strip.length.zero?
|
24
42
|
end
|
25
43
|
end
|
26
44
|
end
|
data/lib/dotenv/version.rb
CHANGED
data/lib/dotenv.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "dotenv/version"
|
1
2
|
require "dotenv/parser"
|
2
3
|
require "dotenv/environment"
|
3
4
|
require "dotenv/missing_keys"
|
@@ -74,6 +75,9 @@ module Dotenv
|
|
74
75
|
# @param env [Hash] Hash of keys and values to restore, defaults to the last saved state
|
75
76
|
# @param safe [Boolean] Is it safe to modify `ENV`? Defaults to `true` in the main thread, otherwise raises an error.
|
76
77
|
def restore(env = @diff&.a, safe: Thread.current == Thread.main)
|
78
|
+
# No previously saved or provided state to restore
|
79
|
+
return unless env
|
80
|
+
|
77
81
|
diff = Dotenv::Diff.new(b: env)
|
78
82
|
return unless diff.any?
|
79
83
|
|
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: 3.1.
|
4
|
+
version: 3.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -83,7 +83,8 @@ files:
|
|
83
83
|
homepage: https://github.com/bkeepers/dotenv
|
84
84
|
licenses:
|
85
85
|
- MIT
|
86
|
-
metadata:
|
86
|
+
metadata:
|
87
|
+
changelog_uri: https://github.com/bkeepers/dotenv/releases
|
87
88
|
post_install_message:
|
88
89
|
rdoc_options: []
|
89
90
|
require_paths:
|
@@ -99,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
- !ruby/object:Gem::Version
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
|
-
rubygems_version: 3.5.
|
103
|
+
rubygems_version: 3.5.16
|
103
104
|
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: Loads environment variables from `.env`.
|