lucid-utils 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +4 -0
- data/lib/lucid/utils/config_from_file.rb +36 -0
- data/lib/lucid/utils/version.rb +7 -0
- data/lib/lucid/utils.rb +8 -0
- data/lib/lucid-utils.rb +1 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a92ccf260f8f9135d3aa8bc3c4ebfcb3c48795424a4bdf49a12c9b2641f54aa4
|
4
|
+
data.tar.gz: a4c9529ec821b0ea100e21166233136072f958ae08dfd4c02878b4da6815559f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f09eee100593c5a37dbdb9632ceade74575a73689b826862e25ec34dec356e0c7e3a7ff3554afc5c704a2be6c82f42b6143ede2835eee42e9a894df69ed479ae
|
7
|
+
data.tar.gz: 98c48fc8a73647e290fbf1986c0ddebdefd0c386bf4006a40572d252c34e3b8e8857d043ff09f050e17527d79e678610b492dcaa599080b6f98f3d21ab5f5dfa
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lucid
|
4
|
+
module Utils
|
5
|
+
class ConfigFromFile
|
6
|
+
# @param path [String]
|
7
|
+
# @param env_prefix [String, nil] environment variables override values in the file
|
8
|
+
#
|
9
|
+
# @return [Hash]
|
10
|
+
def call(path, env_prefix: nil)
|
11
|
+
instance_eval(File.read(path)).tap do |result|
|
12
|
+
raise TypeError, 'not and instance of Hash' unless result.is_a?(Hash)
|
13
|
+
end.then do |config|
|
14
|
+
env_prefix ? env_overrides(config, env_prefix) : config
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
# @param config [Hash]
|
20
|
+
# @param env_prefix [String]
|
21
|
+
#
|
22
|
+
# @return [Hash]
|
23
|
+
private def env_overrides(config, env_prefix)
|
24
|
+
config.each_with_object({}) do |(k, v), config|
|
25
|
+
env_key = [env_prefix, k].join('_').upcase
|
26
|
+
|
27
|
+
if v.is_a?(Hash)
|
28
|
+
config[k] = env_overrides(v, env_key)
|
29
|
+
else
|
30
|
+
config[k] = ENV.fetch(env_key, v)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/lucid/utils.rb
ADDED
data/lib/lucid-utils.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
lib/lucid/utils.rb
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lucid-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelsey Judson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-13 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.rb
|
22
|
+
- lib/lucid/utils/config_from_file.rb
|
23
|
+
- lib/lucid/utils/version.rb
|
24
|
+
homepage: https://github.com/lucidnz/gem-lucid-utils
|
25
|
+
licenses:
|
26
|
+
- ISC
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.0.3
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Common helpers for Lucid gems
|
47
|
+
test_files: []
|