dotenv 3.0.2 → 3.1.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 +3 -1
- data/lib/dotenv/rails.rb +10 -6
- data/lib/dotenv/replay_logger.rb +8 -8
- data/lib/dotenv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc708aad5fcaf487b064451b8f47d5b0e402a7c250385f234306ab3c77fcf20
|
4
|
+
data.tar.gz: e939eca5e64f2aef9aeb784bd9765e20a3201057d4ed69c1ea46b1405625920e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7a9b929e7b419a1df9c07bd2dfa7959deea186bc6de9e0e8bdfdc671b7d4c183104715206ac956e81d4689b76d14907dd0a644eb995f4cd48437047e307ad1
|
7
|
+
data.tar.gz: de3d64ad2bf4fbec40e7c253c71de40cf1cab82875293f168c73a5098e7419554362014e6eb0c6339d485c41c12cccad82e0f854fee30f7fef18e7cc4afc26ef
|
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
@@ -4,7 +4,6 @@ unless Gem::Requirement.new(">= 6.1").satisfied_by?(Gem::Version.new(Rails.versi
|
|
4
4
|
return
|
5
5
|
end
|
6
6
|
|
7
|
-
require "dotenv"
|
8
7
|
require "dotenv/replay_logger"
|
9
8
|
require "dotenv/log_subscriber"
|
10
9
|
|
@@ -24,7 +23,7 @@ end
|
|
24
23
|
module Dotenv
|
25
24
|
# Rails integration for using Dotenv to load ENV variables from a file
|
26
25
|
class Rails < ::Rails::Railtie
|
27
|
-
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger,
|
26
|
+
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, to: "config.dotenv"
|
28
27
|
|
29
28
|
def initialize
|
30
29
|
super()
|
@@ -62,6 +61,12 @@ module Dotenv
|
|
62
61
|
::Rails.root || Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd)
|
63
62
|
end
|
64
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
|
+
|
65
70
|
# The current environment that the app is running in.
|
66
71
|
#
|
67
72
|
# When running `rake`, the Rails application is initialized in development, so we have to
|
@@ -89,10 +94,9 @@ module Dotenv
|
|
89
94
|
end
|
90
95
|
|
91
96
|
initializer "dotenv", after: :initialize_logger do |app|
|
92
|
-
|
93
|
-
|
94
|
-
|
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/replay_logger.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module Dotenv
|
2
2
|
# A logger that can be used before the apps real logger is initialized.
|
3
|
-
class ReplayLogger
|
3
|
+
class ReplayLogger < Logger
|
4
4
|
def initialize
|
5
|
+
super(nil) # Doesn't matter what this is, it won't be used.
|
5
6
|
@logs = []
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def respond_to_missing?(name, include_private = false)
|
13
|
-
(include_private ? Logger.instance_methods : Logger.public_instance_methods).include?(name) || super
|
9
|
+
# Override the add method to store logs so we can replay them to a real logger later.
|
10
|
+
def add(*args, &block)
|
11
|
+
@logs.push([args, block])
|
14
12
|
end
|
15
13
|
|
14
|
+
# Replay the store logs to a real logger.
|
16
15
|
def replay(logger)
|
17
|
-
@logs.each { |
|
16
|
+
@logs.each { |args, block| logger.add(*args, &block) }
|
17
|
+
@logs.clear
|
18
18
|
end
|
19
19
|
end
|
20
20
|
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: 3.0
|
4
|
+
version: 3.1.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: 2024-02-
|
11
|
+
date: 2024-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|