dotenv 3.1.7 → 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: a4ad122f937755147ff0cc52552f17b1e1cf8f9a290ff791ac5ba2f8ef8b43c7
4
- data.tar.gz: 3116d767ea5dc67adca867395ea7effbc1b4ee30769223961f8d041d5c34482d
3
+ metadata.gz: d94f968de5def640d49274915a92e82c9dcf9e5783e58fee39fa2b72a9b7ac0d
4
+ data.tar.gz: e892cb84dfbcc7c38bd484f4c747849c52f3050fc170719180c3f79eef63a2ef
5
5
  SHA512:
6
- metadata.gz: 86436a8b6d193590befeb48a29882b9bd5523f8b80fff961faf1feda91cc720b8b44c1e2705bfbebb73836b99684273d49f78b94c09d05a3077e62996473a47c
7
- data.tar.gz: bb6f98a159c821e0f1cb98ab6c3f0b54a109acc3c934770fd6603f7497c047f031c7124f839963f0f5132a12bd2736e25ab2e4c648cfa56589a30b328d03de61
6
+ metadata.gz: 5ce6017a1069f68382d9a0a241130243bc807a388788bd17129ce2a135d10cdb1dd607b8fbb69ce469540114d77014a833dbe2ebc416ae77560c5bf40db09e0c
7
+ data.tar.gz: 301e709c9e0d322668a145ee6cf723a532b2805a6112a6479624b6cd61be0e4b60a42234be611bc1901195f99c799598402b846c257f813744ef286bd0326987
data/README.md CHANGED
@@ -47,7 +47,10 @@ require 'dotenv'
47
47
  Dotenv.load
48
48
  ```
49
49
 
50
- 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`.
51
54
 
52
55
  ```ruby
53
56
  require 'dotenv'
@@ -84,7 +87,7 @@ You can use the `dotenv` executable load `.env` before launching your applicatio
84
87
  $ dotenv ./script.rb
85
88
  ```
86
89
 
87
- The `dotenv` executable also accepts the flag `-f`. Its value should be a comma-separated list of configuration files, in the order of most important to least. All of the files must exist. There _must_ be a space between the flag and its value.
90
+ The `dotenv` executable also accepts the flag `-f`. Its value should be a comma-separated list of configuration files, in the order of the most important to the least important. All of the files must exist. There _must_ be a space between the flag and its value.
88
91
 
89
92
  ```console
90
93
  $ dotenv -f ".env.local,.env" ./script.rb
@@ -314,6 +317,9 @@ Personally, I prefer to commit the `.env` file with development-only settings. T
314
317
 
315
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`.
316
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
+
317
323
  You can also use the `-o` or `--overwrite` flag on the dotenv cli to overwrite existing `ENV` variables.
318
324
 
319
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 = /
@@ -33,6 +33,8 @@ module Dotenv
33
33
  (?:$|\z) # end of line
34
34
  /x
35
35
 
36
+ QUOTED_STRING = /\A(['"])(.*)\1\z/m
37
+
36
38
  class << self
37
39
  attr_reader :substitutions
38
40
 
@@ -75,7 +77,6 @@ module Dotenv
75
77
  !@overwrite && key != "DOTENV_LINEBREAK_MODE" && ENV.key?(key)
76
78
  end
77
79
 
78
- QUOTED_STRING = /\A(['"])(.*)\1\z/m
79
80
  def parse_value(value)
80
81
  # Remove surrounding quotes
81
82
  value = value.strip.sub(QUOTED_STRING, '\2')
@@ -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.7".freeze
2
+ VERSION = "3.2.0".freeze
3
3
  end
data/lib/dotenv.rb CHANGED
@@ -55,7 +55,7 @@ module Dotenv
55
55
  begin
56
56
  env = Environment.new(File.expand_path(filename), overwrite: overwrite)
57
57
  env = block.call(env) if block
58
- rescue Errno::ENOENT
58
+ rescue Errno::ENOENT, Errno::EISDIR
59
59
  raise unless ignore
60
60
  end
61
61
 
@@ -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,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.7
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -85,7 +84,7 @@ licenses:
85
84
  - MIT
86
85
  metadata:
87
86
  changelog_uri: https://github.com/bkeepers/dotenv/releases
88
- post_install_message:
87
+ funding_uri: https://github.com/sponsors/bkeepers
89
88
  rdoc_options: []
90
89
  require_paths:
91
90
  - lib
@@ -100,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
99
  - !ruby/object:Gem::Version
101
100
  version: '0'
102
101
  requirements: []
103
- rubygems_version: 3.5.22
104
- signing_key:
102
+ rubygems_version: 3.6.9
105
103
  specification_version: 4
106
104
  summary: Loads environment variables from `.env`.
107
105
  test_files: []