envl 0.0.5 → 0.0.7

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/envl.rb +27 -9
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 341a20c85eafb1226918c713ea9861e29b6a3063430fee8abb8d5d75b6eb101a
4
- data.tar.gz: 497f8f7ec3c0ab0c9da219c98f2007ec5a761655b88482cb7b3397016b690e59
3
+ metadata.gz: 27b937b24641ec917f90e86e86654085e1d09d5f32d8a2adceb8fe3169565941
4
+ data.tar.gz: 4c3346ee897db277832231f517982b1efc9ffeaac2fb1fb74b0b42c4717625f6
5
5
  SHA512:
6
- metadata.gz: aae876744e38e3a1623cbbe83173365764efe784766a56651cad928ca2d85d73ba156d624b876b80ec3d5a1797f807e6ae443d19e4df13cd23de1aee42261468
7
- data.tar.gz: 79440f6dbf9021128a3167c196c8e76e5e47707a1497d980cf0cbe4489ea524cd4dd5d40ed38cb73956c6ece969773b0ee43f714880af5b616fc9446d02a4c26
6
+ metadata.gz: bd80ad860186cb3152a0c660e7a2fe9aea4320daa59ab449434eb2be5391c8162c031793e32d830697f225d20cd28c9314369dcfe5feb440cfacab052f77b992
7
+ data.tar.gz: 9d30c1309b51458273dad00253b1c493083ee0f2981a8af3be4a758567ff7baf5407f2de17ff2548f6dbe166cf83294ef1b6b1333c2c58884bf7249ffb7bc8c8
data/lib/envl.rb CHANGED
@@ -3,29 +3,47 @@
3
3
  class Envl
4
4
  @@loaded_vars = []
5
5
 
6
- # automatically finds all .env files and loads them into ENV.
6
+ # Automatically finds all .env files and loads them into ENV.
7
7
  def self.auto_load
8
8
  files = ['*.env', '*.env.*'].map { |s| Dir.glob(s, File::FNM_CASEFOLD) }.flatten.uniq
9
9
  self.load(files)
10
10
  end
11
11
 
12
- def self.get_loaded_vars
12
+ # Returns true if a given file is a .env file.
13
+ def self.is_env?(file)
14
+ ext = File.extname(file).downcase
15
+ name = File.basename(file).downcase
16
+ ext.include? '.env' or name[name.index('.')..].include? '.env'
17
+ end
18
+
19
+ # Returns all keys loaded into ENV.
20
+ def self.keys
13
21
  @@loaded_vars
14
22
  end
15
23
 
16
- # accepts an array of .env files and load thems into ENV.
24
+ # Finds and loads all .env files in a specific directory into ENV.
25
+ def self.load_path(path)
26
+ files = [File.join(path, '*.env'), File.join(path, '*.env.*')].map { |s| Dir.glob(s, File::FNM_CASEFOLD) }.flatten.uniq
27
+ self.load(files)
28
+ end
29
+
30
+ # Loads a single .env file into ENV.
31
+ def self.load_single(path)
32
+ self.load([path])
33
+ end
34
+
35
+ # Accepts an array of .env files and load thems into ENV.
17
36
  def self.load(files)
18
- @@loaded_vars = []
19
37
  files.each do |f|
20
- self.load_file(f)
38
+ self.load_env(f)
21
39
  end
22
40
  ENV
23
41
  end
24
42
 
25
- # loads a single .env file into ENV.
26
- def self.load_file(file)
43
+ # Loads a single .env file into ENV.
44
+ def self.load_env(file)
27
45
  begin
28
- return if not ['.env'].include? File.extname(file).downcase
46
+ return if not self.is_env?(file)
29
47
 
30
48
  File.readlines(file).each do |line|
31
49
  tokens = line.split('=').map {|s| s.strip }
@@ -33,7 +51,7 @@ class Envl
33
51
  key = tokens[0].strip
34
52
  value = tokens[1].gsub("'", '')
35
53
  ENV[key] = value
36
- @@loaded_vars << key
54
+ @@loaded_vars << key if not @@loaded_vars.include? key
37
55
  end
38
56
  end
39
57
  rescue => error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-12 00:00:00.000000000 Z
11
+ date: 2023-02-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple environment variable loader that reads .env files into ENV.
14
14
  email: scott@fuseraft.com
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  requirements: []
40
- rubygems_version: 3.1.6
40
+ rubygems_version: 3.3.5
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: A simple environment variable loader.