dotenv 3.0.3 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/lib/dotenv/rails.rb +10 -6
- data/lib/dotenv/template.rb +24 -6
- data/lib/dotenv/version.rb +1 -1
- data/lib/dotenv.rb +4 -0
- 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: d3fca48323763736621b7583f5966beedfbb8554f9b63d8f4f7373cc7b7dd0d6
|
4
|
+
data.tar.gz: 5941e3b3db44e1e0ab920032ab3a42f372fbd92d3ab71513927993b9e5a931fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e8adbe4289687b34576e9f4907e8a87b68696cb2f6a9126e897716acd1bb0ccc483844bba3619b3a0097569e6da92922d2a3d0062dc228088839e52977ecb3a
|
7
|
+
data.tar.gz: 1398646f0512ea95134323e44058c3997c7b5943408ff81d4d218c8b0f399e1414284e0d9edcc47b785eb470533daba065cf210aa5f150f2359996d5b15618c1
|
data/README.md
CHANGED
@@ -54,7 +54,7 @@ require 'dotenv'
|
|
54
54
|
Dotenv.load('file1.env', 'file2.env')
|
55
55
|
```
|
56
56
|
|
57
|
-
|
57
|
+
### Autorestore in tests
|
58
58
|
|
59
59
|
Since 3.0, dotenv in a Rails app will automatically restore `ENV` after each test. This means you can modify `ENV` in your tests without fear of leaking state to other tests. It works with both `ActiveSupport::TestCase` and `Rspec`.
|
60
60
|
|
@@ -181,6 +181,8 @@ Available options:
|
|
181
181
|
|
182
182
|
* `Dotenv::Rails.files` - list of files to be loaded, in order of precedence.
|
183
183
|
* `Dotenv::Rails.overwrite` - Overwrite exiting `ENV` variables with contents of `.env*` files
|
184
|
+
* `Dotenv::Rails.logger` - The logger to use for dotenv's logging. Defaults to `Rails.logger`
|
185
|
+
* `Dotenv::Rails.autorestore` - Enable or disable [autorestore](#autorestore-in-tests)
|
184
186
|
|
185
187
|
### Multi-line values
|
186
188
|
|
data/lib/dotenv/rails.rb
CHANGED
@@ -23,7 +23,7 @@ end
|
|
23
23
|
module Dotenv
|
24
24
|
# Rails integration for using Dotenv to load ENV variables from a file
|
25
25
|
class Rails < ::Rails::Railtie
|
26
|
-
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger,
|
26
|
+
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, to: "config.dotenv"
|
27
27
|
|
28
28
|
def initialize
|
29
29
|
super()
|
@@ -61,6 +61,12 @@ module Dotenv
|
|
61
61
|
::Rails.root || Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd)
|
62
62
|
end
|
63
63
|
|
64
|
+
# Set a new logger and replay logs
|
65
|
+
def logger=(new_logger)
|
66
|
+
logger.replay new_logger if logger.is_a?(ReplayLogger)
|
67
|
+
config.dotenv.logger = new_logger
|
68
|
+
end
|
69
|
+
|
64
70
|
# The current environment that the app is running in.
|
65
71
|
#
|
66
72
|
# When running `rake`, the Rails application is initialized in development, so we have to
|
@@ -88,11 +94,9 @@ module Dotenv
|
|
88
94
|
end
|
89
95
|
|
90
96
|
initializer "dotenv", after: :initialize_logger do |app|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
logger.replay new_logger if logger.respond_to?(:replay)
|
95
|
-
self.logger = new_logger
|
97
|
+
if logger.is_a?(ReplayLogger)
|
98
|
+
self.logger = ActiveSupport::TaggedLogging.new(::Rails.logger).tagged("dotenv")
|
99
|
+
end
|
96
100
|
end
|
97
101
|
|
98
102
|
initializer "dotenv.deprecator" do |app|
|
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.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -84,7 +84,7 @@ homepage: https://github.com/bkeepers/dotenv
|
|
84
84
|
licenses:
|
85
85
|
- MIT
|
86
86
|
metadata: {}
|
87
|
-
post_install_message:
|
87
|
+
post_install_message:
|
88
88
|
rdoc_options: []
|
89
89
|
require_paths:
|
90
90
|
- lib
|
@@ -99,8 +99,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
103
|
-
signing_key:
|
102
|
+
rubygems_version: 3.5.9
|
103
|
+
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Loads environment variables from `.env`.
|
106
106
|
test_files: []
|