dotenvx 4.0.0-x86_64-linux

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 44d08d55899e58515b0e39e447db6cb3d67c274869d8a7c30d8a4f982beca08c
4
+ data.tar.gz: 7f51dd64512d1ec4b3ca06480a45cf67efc0839b183d36e59b525dd6b5d42491
5
+ SHA512:
6
+ metadata.gz: afb09d52f18138dd5669860727a7cbea047d30f390bb4bc7046a38510c2e21d14dc67d951e860e5d8ccdc25864ca5720d09411bf3fc8c65177456a76193e6764
7
+ data.tar.gz: b23da2b9b513d2dd9b1ddaee1e7bd07ff9957aeb3b36b65fc10fca07b4f8ba94a35ed0aa58c262ac037ceb9eafd50be4eb91ff25f225f7f4cfa1c6c0a66a00a5
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx-ruby/compare/v4.0.0...main)
6
+
7
+ ## [4.0.0](https://github.com/dotenvx/dotenvx-ruby/compare/v0.0.2...v4.0.0)
8
+
9
+ - Load plaintext and encrypted dotenv files through `dotenvx-primitives`.
10
+ - Bundle the Rust implementation as a Magnus native extension.
11
+ - Match the conventional Ruby dotenv loading, parsing, overwrite, and strict
12
+ missing-file APIs.
13
+ - Publish native `dotenvx` gems for Linux, macOS, and Windows from one tag.
14
+
15
+ ## 0.1.0 and prior
16
+
17
+ Please see commit history.
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, Scott Motte
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ [![dotenvx](https://dotenvx.com/better-banner.png)](https://dotenvx.com)
2
+
3
+ *a secure dotenv–from the creator of [`dotenv`](https://github.com/motdotla/dotenv).*
4
+
5
+ `dotenvx` loads plaintext and encrypted dotenv files through the shared
6
+ [`dotenvx-primitives`](https://crates.io/crates/dotenvx-primitives) Rust
7
+ implementation. The native extension is bundled in the gem; users do not need
8
+ Node.js, a dotenvx CLI, or a Rust toolchain.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ gem install dotenvx
14
+ ```
15
+
16
+ Or add it to a Gemfile:
17
+
18
+ ```ruby
19
+ gem "dotenvx"
20
+ ```
21
+
22
+ ## Use
23
+
24
+ Load `.env` from the current directory:
25
+
26
+ ```ruby
27
+ require "dotenvx/load"
28
+ ```
29
+
30
+ Or load explicitly:
31
+
32
+ ```ruby
33
+ require "dotenvx"
34
+
35
+ Dotenvx.load
36
+ Dotenvx.load(".env.local", ".env")
37
+ ```
38
+
39
+ Existing environment variables win by default:
40
+
41
+ ```ruby
42
+ Dotenvx.load(".env")
43
+ ```
44
+
45
+ To replace existing values:
46
+
47
+ ```ruby
48
+ Dotenvx.load(".env", overwrite: true)
49
+ Dotenvx.overwrite(".env")
50
+ ```
51
+
52
+ Parse without changing `ENV`:
53
+
54
+ ```ruby
55
+ values = Dotenvx.parse(".env")
56
+ ```
57
+
58
+ Raise when a file is missing:
59
+
60
+ ```ruby
61
+ Dotenvx.load!(".env")
62
+ ```
63
+
64
+ Require configuration keys:
65
+
66
+ ```ruby
67
+ Dotenvx.require_keys("DATABASE_URL", "SECRET_KEY")
68
+ ```
69
+
70
+ Encrypted values are decrypted automatically when the matching private key is
71
+ available through the process environment, `<filename>.keys`, or `.env.keys`.
72
+
73
+ ## Native platforms
74
+
75
+ Tagged releases publish variants of the same `dotenvx` gem for:
76
+
77
+ - Linux x86-64
78
+ - Linux ARM64
79
+ - macOS Intel
80
+ - macOS Apple Silicon
81
+ - Windows x64
82
+
83
+ RubyGems selects the correct variant during `gem install dotenvx`.
Binary file
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dotenvx"
4
+
5
+ Dotenvx.load
@@ -0,0 +1,62 @@
1
+ require "dotenvx"
2
+ require "active_support/notifications"
3
+ require "rails/railtie"
4
+ require "pathname"
5
+
6
+ # Fix for rake tasks loading in development
7
+ #
8
+ # Dotenv loads environment variables when the Rails application is initialized.
9
+ # When running `rake`, the Rails application is initialized in development.
10
+ # Rails includes some hacks to set `RAILS_ENV=test` when running `rake test`,
11
+ # but rspec does not include the same hacks.
12
+ #
13
+ # See https://github.com/bkeepers/dotenv/issues/219
14
+ if defined?(Rake.application)
15
+ task_regular_expression = /^(default$|parallel:spec|spec(:|$))/
16
+ if Rake.application.top_level_tasks.grep(task_regular_expression).any?
17
+ environment = Rake.application.options.show_tasks ? "development" : "test"
18
+ Rails.env = ENV["RAILS_ENV"] ||= environment
19
+ end
20
+ end
21
+
22
+ Dotenvx.instrumenter = ActiveSupport::Notifications
23
+
24
+ # Watch all loaded env files with Spring
25
+ begin
26
+ require "spring/commands"
27
+ ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
28
+ event = ActiveSupport::Notifications::Event.new(*args)
29
+ Spring.watch event.payload[:env].filename if Rails.application
30
+ end
31
+ rescue LoadError, ArgumentError
32
+ # Spring is not available
33
+ end
34
+
35
+ module Dotenvx
36
+ class Railtie < Rails::Railtie
37
+ config.before_configuration { Dotenvx::Railtie.instance.load }
38
+
39
+ def load
40
+ Dotenvx.load(*dotenvx_files)
41
+ end
42
+
43
+ private
44
+
45
+ def dotenvx_files
46
+ environment = Rails.env
47
+ files = [
48
+ root.join(".env.#{environment}.local")
49
+ ]
50
+ files << root.join(".env.local") unless environment == "test"
51
+ files.concat([
52
+ root.join(".env.#{environment}"),
53
+ root.join(".env")
54
+ ])
55
+ files
56
+ end
57
+
58
+ def root
59
+ Pathname.new(Rails.root || ENV["RAILS_ROOT"] || Dir.pwd)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module Dotenvx
2
+ VERSION = "4.0.0"
3
+ end
data/lib/dotenvx.rb ADDED
@@ -0,0 +1,108 @@
1
+ require "dotenvx/version"
2
+ require "dotenvx/dotenvx_native"
3
+
4
+ module Dotenvx
5
+ class MissingKeys < RuntimeError
6
+ attr_reader :keys
7
+
8
+ def initialize(keys)
9
+ @keys = keys
10
+ super("Missing required configuration keys: #{keys.join(", ")}")
11
+ end
12
+ end
13
+
14
+ class << self
15
+ attr_accessor :instrumenter
16
+
17
+ def load(*filenames, overwrite: false, ignore: true)
18
+ env = parse(*filenames, overwrite: overwrite, ignore: ignore)
19
+ update(env, overwrite: overwrite)
20
+ end
21
+
22
+ def load!(*filenames)
23
+ load(*filenames, ignore: false)
24
+ end
25
+
26
+ def overwrite(*filenames)
27
+ load(*filenames, overwrite: true)
28
+ end
29
+ alias overload overwrite
30
+
31
+ def overwrite!(*filenames)
32
+ load(*filenames, overwrite: true, ignore: false)
33
+ end
34
+ alias overload! overwrite!
35
+
36
+ def parse(*filenames, overwrite: false, ignore: true)
37
+ filenames = [".env"] if filenames.empty?
38
+ filenames = filenames.flatten.reverse if overwrite
39
+
40
+ process_env = ENV.to_h
41
+ filenames.reduce({}) do |values, filename|
42
+ path = File.expand_path(filename)
43
+ begin
44
+ source = File.binread(path).sub(/\A\xEF\xBB\xBF/, "").force_encoding(Encoding::UTF_8)
45
+ rescue Errno::ENOENT, Errno::EISDIR
46
+ raise unless ignore
47
+ next values
48
+ end
49
+
50
+ parsed, = Native.parse_dotenv(
51
+ source,
52
+ process_env.to_a,
53
+ overwrite == true,
54
+ key_files(path)
55
+ )
56
+ parsed = parsed.to_h
57
+ process_env.merge!(parsed)
58
+ values.merge!(parsed)
59
+ yield Environment.new(path, parsed) if block_given?
60
+ values
61
+ end
62
+ end
63
+
64
+ def update(env = {}, overwrite: false)
65
+ changed = {}
66
+ env.each do |key, value|
67
+ key = key.to_s
68
+ next if ENV.key?(key) && overwrite == false
69
+
70
+ if ENV.key?(key) && overwrite == :warn
71
+ warn "Warning: dotenvx not overwriting ENV[#{key.inspect}]"
72
+ next
73
+ end
74
+ unless [true, false, :warn].include?(overwrite)
75
+ raise ArgumentError, "Invalid value for overwrite: #{overwrite.inspect}"
76
+ end
77
+
78
+ ENV[key] = value.to_s
79
+ changed[key] = value.to_s
80
+ end
81
+ changed
82
+ end
83
+
84
+ def require_keys(*keys)
85
+ missing = keys.flatten.map(&:to_s) - ENV.keys
86
+ raise MissingKeys, missing unless missing.empty?
87
+ end
88
+
89
+ private
90
+
91
+ def key_files(path)
92
+ basename = File.basename(path)
93
+ candidates = ["#{path}.keys"]
94
+ candidates << File.join(File.dirname(path), ".env.keys") unless basename == ".env"
95
+ candidates.select { |candidate| File.file?(candidate) }
96
+ end
97
+ end
98
+
99
+ class Environment < Hash
100
+ attr_reader :filename
101
+
102
+ def initialize(filename, values)
103
+ @filename = filename
104
+ super()
105
+ update(values)
106
+ end
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotenvx
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0
5
+ platform: x86_64-linux
6
+ authors:
7
+ - motdotla
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake-compiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "[dotenvx.com] a better dotenv–from the creator of `dotenv`"
70
+ email:
71
+ - mot@mot.la
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - CHANGELOG.md
77
+ - LICENSE
78
+ - README.md
79
+ - lib/dotenvx.rb
80
+ - lib/dotenvx/dotenvx_native.so
81
+ - lib/dotenvx/load.rb
82
+ - lib/dotenvx/rails.rb
83
+ - lib/dotenvx/version.rb
84
+ homepage: https://github.com/dotenvx/dotenvx-ruby
85
+ licenses:
86
+ - BSD-3-Clause
87
+ metadata:
88
+ homepage_uri: https://github.com/dotenvx/dotenvx-ruby
89
+ source_code_uri: https://github.com/dotenvx/dotenvx-ruby
90
+ changelog_uri: https://github.com/dotenvx/dotenvx-ruby
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.6.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.3.11
105
+ requirements: []
106
+ rubygems_version: 3.3.27
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: "[dotenvx.com] a better dotenv–from the creator of `dotenv`"
110
+ test_files: []