dotenv 3.1.0 → 3.1.2

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
2
  SHA256:
3
- metadata.gz: 1dc708aad5fcaf487b064451b8f47d5b0e402a7c250385f234306ab3c77fcf20
4
- data.tar.gz: e939eca5e64f2aef9aeb784bd9765e20a3201057d4ed69c1ea46b1405625920e
3
+ metadata.gz: 93520ca26942608e2d61ddae13f7b6d1cdd16e83e36d6cd9c770282149b2f441
4
+ data.tar.gz: bd58a9b3c59d7b6bad8327c1af4a69532ce5a4febb5a408f8a3a3874d3de6925
5
5
  SHA512:
6
- metadata.gz: 3c7a9b929e7b419a1df9c07bd2dfa7959deea186bc6de9e0e8bdfdc671b7d4c183104715206ac956e81d4689b76d14907dd0a644eb995f4cd48437047e307ad1
7
- data.tar.gz: de3d64ad2bf4fbec40e7c253c71de40cf1cab82875293f168c73a5098e7419554362014e6eb0c6339d485c41c12cccad82e0f854fee30f7fef18e7cc4afc26ef
6
+ metadata.gz: 178f4451234c97f3ad1d1601b62164d9f59fb52a35ad1393d3a924f541c2bc90e8732af795de3ea60acf0ade02ed81472127cebd0eac12d16648315806c58b95
7
+ data.tar.gz: 6ac43f44496d94b52ca8f2d852fa4c7bb095996604ead12a81db9118fac756a9fc89a61191f46cafcd846e8617421f7bfac62304c058def1c9d8915b1af47943
data/lib/dotenv/diff.rb CHANGED
@@ -50,7 +50,10 @@ module Dotenv
50
50
  private
51
51
 
52
52
  def snapshot
53
- ENV.to_h.freeze
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
@@ -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
- env_template.puts template_line(line)
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
- def template_line(line)
20
- var, value = line.split("=")
21
- template = var.gsub(EXPORT_COMMAND, "")
22
- is_a_comment = var.strip[0].eql?("#")
23
- (value.nil? || is_a_comment) ? line : "#{var}=#{template}"
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
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "3.1.0".freeze
2
+ VERSION = "3.1.2".freeze
3
3
  end
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.0
4
+ version: 3.1.2
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-27 00:00:00.000000000 Z
11
+ date: 2024-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
99
  - !ruby/object:Gem::Version
100
100
  version: '0'
101
101
  requirements: []
102
- rubygems_version: 3.5.3
102
+ rubygems_version: 3.5.9
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Loads environment variables from `.env`.