philiprehberger-env_loader 0.2.0 → 0.3.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: f7bda9ba33185eb43d4c7075a8fff984bfd0c2c74616414a987f650366c84805
4
- data.tar.gz: 9de085c7594eb86b5e5611e6c3acb2c1e1480666aa713b32440238850f65b8ba
3
+ metadata.gz: 5695fc29c75310a93a32d21ca2b7b1919771d2ef434b79e1142ff0386cc87248
4
+ data.tar.gz: 45bc9bbf6d34968df565216ea9bf42030c7abe6d52d0b5b6a9888e966bb62ee1
5
5
  SHA512:
6
- metadata.gz: ca16348ef8d38e61cff91d8bf4b9dbf2313f1115840cc7f029f15c818baa466e98bb4185a7569fbe898b5b8182206a2bb612403747ecb98c585370c89bcc92c4
7
- data.tar.gz: 4f0f69b2371534485cd84f1704e49fbc5ca29551f917a042a757f3f167eb9b45eba0f01ebbf19a613d38ed8645728ac6cc75faeda065ce993b04a8e414a8f6bd
6
+ metadata.gz: ca424e6b156ec4b4aa011b5120cf97bd9fe58e2e7de23e992b81f130cb6cb6372e01aa836a8fdd2e3997061fe0fdfcb7e382f1729207fc07002e290c609a35e1
7
+ data.tar.gz: 3405dd52700c5ede06248dc1fffe2ea3d983061641100429aac85c74f2e1724f783e10559b09a72fb46c63f943e1d7b3908b11e073d327eb4e6a6f9077d07cb1
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-05-01
11
+
12
+ ### Added
13
+ - `EnvLoader.parse(content)` — parse `.env`-formatted content from a string into a hash without touching ENV; useful for tests and embedded configs
14
+
15
+ ## [0.2.1] - 2026-04-15
16
+
17
+ ### Changed
18
+ - Verified compliance with Ruby package, gemspec, and README guides
19
+
10
20
  ## [0.2.0] - 2026-04-04
11
21
 
12
22
  ### Added
data/README.md CHANGED
@@ -73,6 +73,21 @@ Philiprehberger::EnvLoader.generate_template(
73
73
  )
74
74
  ```
75
75
 
76
+ ### Parse from a String
77
+
78
+ Parse `.env`-formatted text without reading from disk and without touching ENV:
79
+
80
+ ```ruby
81
+ content = <<~ENV
82
+ APP_HOST=localhost
83
+ APP_PORT=3000
84
+ # comments and blank lines are ignored
85
+ ENV
86
+
87
+ Philiprehberger::EnvLoader.parse(content)
88
+ # => { "APP_HOST" => "localhost", "APP_PORT" => "3000" }
89
+ ```
90
+
76
91
  ## API
77
92
 
78
93
  | Method | Description |
@@ -80,6 +95,7 @@ Philiprehberger::EnvLoader.generate_template(
80
95
  | `.load(*files, required:, types:, defaults:, prefix:, strip_prefix:)` | Load variables from .env files with options |
81
96
  | `.validate!(*keys)` | Raise if any keys are missing or empty in ENV |
82
97
  | `.generate_template(output:, keys:)` | Generate a .env.template file |
98
+ | `.parse(content)` | Parse `.env`-formatted content from a string into a hash without touching ENV |
83
99
  | `EnvLoader::Error` | Base error class for all gem errors |
84
100
  | `EnvLoader::ValidationError` | Raised when required keys are missing or empty |
85
101
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module EnvLoader
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
@@ -65,13 +65,18 @@ module Philiprehberger
65
65
  File.write(output, "#{content}\n")
66
66
  end
67
67
 
68
- # Parse a .env file into a hash of key-value pairs.
68
+ # Parse `.env`-formatted content from a string into a hash.
69
69
  #
70
- # @param path [String] the file path
71
- # @return [Hash<String, String>] parsed key-value pairs
72
- def self.parse_file(path)
70
+ # Useful for tests, embedded configurations, and any scenario where the
71
+ # `.env` content does not live in a file. Comments (`#`), blank lines,
72
+ # and surrounding whitespace are ignored. Single- and double-quoted
73
+ # values are unwrapped. ENV is not touched.
74
+ #
75
+ # @param content [String] the `.env`-formatted text
76
+ # @return [Hash{String => String}] parsed key-value pairs
77
+ def self.parse(content)
73
78
  result = {}
74
- File.readlines(path).each do |line|
79
+ content.to_s.each_line do |line|
75
80
  line = line.strip
76
81
  next if line.empty? || line.start_with?('#')
77
82
 
@@ -86,6 +91,14 @@ module Philiprehberger
86
91
  end
87
92
  result
88
93
  end
94
+
95
+ # Parse a .env file into a hash of key-value pairs.
96
+ #
97
+ # @param path [String] the file path
98
+ # @return [Hash<String, String>] parsed key-value pairs
99
+ def self.parse_file(path)
100
+ parse(File.read(path))
101
+ end
89
102
  private_class_method :parse_file
90
103
 
91
104
  # Apply type coercions to ENV values.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-env_loader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-05 00:00:00.000000000 Z
11
+ date: 2026-05-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Load environment variables from multiple .env files with configurable
14
14
  precedence, type coercion, required key validation, default values, and template