lucid_utils 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 374e47d393dbd815c51380a50a7ef009f83d07a6339ed4a1c92c79ee2b273394
4
+ data.tar.gz: 51ade2f04cddd4b8b625ace3666e050d89c9d362b34847fc94aa9322a35416cc
5
+ SHA512:
6
+ metadata.gz: 57b919edbf5adf5e3c248ced0e71c7e5bd163c59795345a0f4e3c4da602b6c83564502505db1cad99b6138ff3af1b9d22791eb39bd031343787eaf00acb43d64
7
+ data.tar.gz: 9854b6d3d9e05a22dd4f3ccdd86b181d6553e45d7a25ce71c0443c19b51b8802665bf78d5cbd6d729b7a5e41e74191878dfff3ea8fc633646d30274ec5693357
@@ -0,0 +1,4 @@
1
+ lucid_utils
2
+ ===========
3
+
4
+ ...
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucidUtils
4
+ autoload :ConfigFromFile, 'lucid_utils/config_from_file'
5
+ autoload :VERSION, 'lucid_utils/version'
6
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucidUtils
4
+ class ConfigFromFile
5
+ #
6
+ # @param path [String]
7
+ # @param env_prefix [String, nil] environment variables override values in the file
8
+ #
9
+ # @return [Hash]
10
+ #
11
+ def call(path, env_prefix: nil)
12
+ instance_eval(File.read(path)).tap do |result|
13
+ raise TypeError, 'not and instance of Hash' unless result.is_a?(Hash)
14
+ end.then do |config|
15
+ env_prefix ? env_overrides(config, env_prefix) : config
16
+ end
17
+ end
18
+
19
+
20
+ #
21
+ # @param config [Hash]
22
+ # @param env_prefix [String]
23
+ #
24
+ # @return [Hash]
25
+ #
26
+ private def env_overrides(config, env_prefix)
27
+ config.each_with_object({}) do |(k, v), config|
28
+ env_key = [env_prefix, k].join('_').upcase
29
+
30
+ if v.is_a?(Hash)
31
+ config[k] = env_overrides(v, env_key)
32
+ else
33
+ config[k] = ENV.fetch(env_key, v)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucidUtils
4
+ VERSION = '0.0.1'
5
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lucid_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kelsey Judson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: kelsey@lucid.nz
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/lucid_utils.rb
21
+ - lib/lucid_utils/config_from_file.rb
22
+ - lib/lucid_utils/version.rb
23
+ homepage: https://github.com/lucidnz/gem-lucid_utils
24
+ licenses:
25
+ - ISC
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Common helpers for Lucid gems
46
+ test_files: []