gonfic 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gonfic/version.rb +1 -1
  3. data/lib/gonfic.rb +26 -9
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14e15052de540978cafed0765ee7799009e3090aabea1aa603520c4f663ce5d2
4
- data.tar.gz: 628692d67ffafb2e96b2442817f2549b804a3d2d01370f0b12019d54bfb7bcd7
3
+ metadata.gz: 7b8810655c20a36c4ae9220d82652bd740f7a9b108f62fa6c34400c39d8af4d0
4
+ data.tar.gz: 4202e4993d903c3fe560730ff88e798728617f2db71d92bc9f5de1127ca30888
5
5
  SHA512:
6
- metadata.gz: 40db1c5163d6e7654def37a1769b3ca1de9d8fb669e324cb4b1f0d35f192bf9cc5682a85d18eab82f5ad49c9ec62d60036f8496238946a2c7f4793cacd4de728
7
- data.tar.gz: 67a77a4d33896fbced469633dcd5fa82e513abf97fe8349c8d7713c940b5d32dbd96fd4a9d8f0c608971f489d06beef4e84dd33671b1f1fcdb9967ef7b0f298e
6
+ metadata.gz: 4dd9ed806e8982e2be4103930ab51291b3c93c4163f044b5ebbdd63edc72b6bf369d4b2be8c597c5da66a8d83bce4e116171f1021c4238284e54cc6a3f36092b
7
+ data.tar.gz: 6828d7979ccc5589531c81d2f4f063fcf5d8511749f97445d58c6a8aff6ce2befa75a808d67f6f1e8db89d843a837cee237a5feb40a981146e9567b9a1473432
@@ -1,3 +1,3 @@
1
1
  module Gonfic
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.2'.freeze
3
3
  end
data/lib/gonfic.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  require_relative 'gonfic/version'
2
4
  require_relative 'gonfic/config'
3
5
  require_relative 'gonfic/env_extractor'
@@ -12,16 +14,25 @@ module Gonfic
12
14
  filename: nil, file_loader: YAML_FILE_LOADER, directories: Directories.home_then_here,
13
15
  env_variable_prefix: EnvExtractor.env_prefix_from_filename(filename)
14
16
  )
15
- config = Config.new(defaults)
16
- if filename
17
- directories.each do |directory|
18
- config.merge!(load_configuration_file(File.join(directory, filename), file_loader))
19
- end
20
- end
21
- if env_variable_prefix
22
- config.merge!(EnvExtractor.extract_variables_from_env(prefix: env_variable_prefix, defaults: defaults))
17
+ configs =
18
+ configs_from_defaults(defaults: defaults) +
19
+ configs_from_files(filename: filename, file_loader: file_loader, directories: directories) +
20
+ configs_from_env(env_variable_prefix: env_variable_prefix, defaults: defaults)
21
+
22
+ configs.reduce(:merge!)
23
+ end
24
+
25
+ def self.configs_from_defaults(defaults:)
26
+ [Config.new(defaults)]
27
+ end
28
+
29
+ def self.configs_from_files(filename:, file_loader:, directories:)
30
+ return [] unless filename
31
+
32
+ directories.map do |directory|
33
+ filepath = File.expand_path(File.join(directory, filename))
34
+ load_configuration_file(filepath, file_loader)
23
35
  end
24
- config
25
36
  end
26
37
 
27
38
  def self.load_configuration_file(filename, file_loader)
@@ -32,4 +43,10 @@ module Gonfic
32
43
  Hashie.logger.error(e)
33
44
  {}
34
45
  end
46
+
47
+ def self.configs_from_env(env_variable_prefix:, defaults:)
48
+ return [] unless env_variable_prefix
49
+
50
+ [EnvExtractor.extract_variables_from_env(prefix: env_variable_prefix, defaults: defaults)]
51
+ end
35
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gonfic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Chludziński
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-31 00:00:00.000000000 Z
11
+ date: 2023-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie