dotenv 3.1.8 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 586dd937a4a5a27f37fb6c71d64498ba9c84854d36d761cd1e1759f6cf130710
4
- data.tar.gz: c3c8aad2fa4666f59833edc8baa77a2e127350a5987208c6c96b6a0f4ac55e98
3
+ metadata.gz: d94f968de5def640d49274915a92e82c9dcf9e5783e58fee39fa2b72a9b7ac0d
4
+ data.tar.gz: e892cb84dfbcc7c38bd484f4c747849c52f3050fc170719180c3f79eef63a2ef
5
5
  SHA512:
6
- metadata.gz: d77998e7079602e9e2114cea2fcc9a119be0f9fcbc5d962d687c72df0239bf6ae93a66502fb856abaaa0b12dd14960ef08bc990d75fc3bca87ec8b08f8f17ea6
7
- data.tar.gz: a669c1d1bc64af5cb3e3eafafdab2877adf5bfcf7d8b72b90d47bfcdad441afd77c8a55742660a46ab75b34ac8bc447c82a6b86b52f2714366382737eb72efa3
6
+ metadata.gz: 5ce6017a1069f68382d9a0a241130243bc807a388788bd17129ce2a135d10cdb1dd607b8fbb69ce469540114d77014a833dbe2ebc416ae77560c5bf40db09e0c
7
+ data.tar.gz: 301e709c9e0d322668a145ee6cf723a532b2805a6112a6479624b6cd61be0e4b60a42234be611bc1901195f99c799598402b846c257f813744ef286bd0326987
data/README.md CHANGED
@@ -2,11 +2,6 @@
2
2
 
3
3
  Shim to load environment variables from `.env` into `ENV` in *development*.
4
4
 
5
- <img align="left" src="https://github.com/user-attachments/assets/0052ed0b-00d2-416a-bdaa-0466c0226933" width="80" />
6
- <div><sup>Dotenv is proud to be <a href="https://github.com/sponsors/bkeepers">sponsored by</a>:</sup></div>
7
- <strong><a href="https://bit.ly/dotenv-stoked-seagull">Stoked Seagull Software</a></strong>
8
- <div>Need help with a software project but don't know where to begin? <a href="https://bit.ly/dotenv-stoked-seagull">Stoked Seagull can help.</a></div><br><br>
9
-
10
5
  Storing [configuration in the environment](http://12factor.net/config) is one of the tenets of a [twelve-factor app](http://12factor.net). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables.
11
6
 
12
7
  But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped.
@@ -52,7 +47,10 @@ require 'dotenv'
52
47
  Dotenv.load
53
48
  ```
54
49
 
55
- By default, `load` will look for a file called `.env` in the current working directory. Pass in multiple files and they will be loaded in order. The first value set for a variable will win.
50
+ By default, `load` will look for a file called `.env` in the current working directory.
51
+ Pass in multiple files and they will be loaded in order.
52
+ The first value set for a variable will win.
53
+ Existing environment variables will not be overwritten unless you set `overwrite: true`.
56
54
 
57
55
  ```ruby
58
56
  require 'dotenv'
@@ -319,6 +317,9 @@ Personally, I prefer to commit the `.env` file with development-only settings. T
319
317
 
320
318
  By default, it **won't** overwrite existing environment variables as dotenv assumes the deployment environment has more knowledge about configuration than the application does. To overwrite existing environment variables you can use `Dotenv.load files, overwrite: true`.
321
319
 
320
+ To warn when a value was not overwritten (e.g. to make users aware of this gotcha),
321
+ use `Dotenv.load files, overwrite: :warn`.
322
+
322
323
  You can also use the `-o` or `--overwrite` flag on the dotenv cli to overwrite existing `ENV` variables.
323
324
 
324
325
  ```console
@@ -24,7 +24,7 @@ module Dotenv
24
24
  def update(event)
25
25
  diff = event.payload[:diff]
26
26
  changed = diff.env.keys.map { |key| color_var(key) }
27
- debug "Set #{changed.to_sentence}" if diff.any?
27
+ debug "Set #{changed.join(", ")}" if diff.any?
28
28
  end
29
29
 
30
30
  def save(event)
@@ -39,8 +39,8 @@ module Dotenv
39
39
 
40
40
  if removed.any? || restored.any?
41
41
  info "Restored snapshot of #{color_env_constant}"
42
- debug "Unset #{removed.to_sentence}" if removed.any?
43
- debug "Restored #{restored.to_sentence}" if restored.any?
42
+ debug "Unset #{removed.join(", ")}" if removed.any?
43
+ debug "Restored #{restored.join(", ")}" if restored.any?
44
44
  end
45
45
  end
46
46
 
@@ -3,7 +3,7 @@ module Dotenv
3
3
 
4
4
  class MissingKeys < Error # :nodoc:
5
5
  def initialize(keys)
6
- key_word = "key#{(keys.size > 1) ? "s" : ""}"
6
+ key_word = "key#{"s" if keys.size > 1}"
7
7
  super("Missing required configuration #{key_word}: #{keys.inspect}")
8
8
  end
9
9
  end
data/lib/dotenv/parser.rb CHANGED
@@ -9,8 +9,8 @@ module Dotenv
9
9
  # It allows for variable substitutions, command substitutions, and exporting of variables.
10
10
  class Parser
11
11
  @substitutions = [
12
- Dotenv::Substitutions::Variable,
13
- Dotenv::Substitutions::Command
12
+ Dotenv::Substitutions::Command,
13
+ Dotenv::Substitutions::Variable
14
14
  ]
15
15
 
16
16
  LINE = /
@@ -20,7 +20,7 @@ module Dotenv
20
20
  )
21
21
  /x
22
22
 
23
- def call(value, _env)
23
+ def call(value, env)
24
24
  # Process interpolated shell commands
25
25
  value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
26
26
  # Eliminate opening and closing parentheses
@@ -31,7 +31,7 @@ module Dotenv
31
31
  $LAST_MATCH_INFO[0][1..]
32
32
  else
33
33
  # Execute the command and return the value
34
- `#{command}`.chomp
34
+ `#{Variable.call(command, env)}`.chomp
35
35
  end
36
36
  end
37
37
  end
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "3.1.8".freeze
2
+ VERSION = "3.2.0".freeze
3
3
  end
data/lib/dotenv.rb CHANGED
@@ -94,13 +94,21 @@ module Dotenv
94
94
  # Update `ENV` with the given hash of keys and values
95
95
  #
96
96
  # @param env [Hash] Hash of keys and values to set in `ENV`
97
- # @param overwrite [Boolean] Overwrite existing `ENV` values
97
+ # @param overwrite [Boolean|:warn] Overwrite existing `ENV` values
98
98
  def update(env = {}, overwrite: false)
99
99
  instrument(:update) do |payload|
100
100
  diff = payload[:diff] = Dotenv::Diff.new do
101
101
  ENV.update(env.transform_keys(&:to_s)) do |key, old_value, new_value|
102
102
  # This block is called when a key exists. Return the new value if overwrite is true.
103
- overwrite ? new_value : old_value
103
+ case overwrite
104
+ when :warn
105
+ # not printing the value since that could be a secret
106
+ warn "Warning: dotenv not overwriting ENV[#{key.inspect}]"
107
+ old_value
108
+ when true then new_value
109
+ when false then old_value
110
+ else raise ArgumentError, "Invalid value for overwrite: #{overwrite.inspect}"
111
+ end
104
112
  end
105
113
  end
106
114
  diff.env
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.8
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  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.6.2
102
+ rubygems_version: 3.6.9
103
103
  specification_version: 4
104
104
  summary: Loads environment variables from `.env`.
105
105
  test_files: []