@@ -42,17 +42,8 @@ def load(identifier, should_log = true)
4242 file = CONFIG_DIRECTORY + "#{ identifier } .yml"
4343
4444 if file . exist?
45- configuration = YAML . load_file ( file )
46- logger . debug { "Configuration from #{ file } : #{ configuration } " } if should_log
47-
4845 user_provided = ENV [ environment_variable_name ( identifier ) ]
49-
50- if user_provided
51- YAML . load ( user_provided ) . each do |new_prop |
52- configuration = do_merge ( configuration , new_prop , should_log )
53- end
54- logger . debug { "Configuration from #{ file } modified with: #{ user_provided } " } if should_log
55- end
46+ configuration = load_configuration ( file , user_provided , should_log )
5647 else
5748 logger . debug { "No configuration file #{ file } found" } if should_log
5849 end
@@ -68,6 +59,27 @@ def load(identifier, should_log = true)
6859
6960 private_constant :CONFIG_DIRECTORY , :ENVIRONMENT_VARIABLE_PATTERN
7061
62+ def load_configuration ( file , user_provided , should_log )
63+ configuration = YAML . load_file ( file )
64+ logger . debug { "Configuration from #{ file } : #{ configuration } " } if should_log
65+
66+ if user_provided
67+ user_provided_value = YAML . load ( user_provided )
68+ if user_provided_value . is_a? ( Hash )
69+ configuration = do_merge ( configuration , user_provided_value , should_log )
70+ elsif user_provided_value . is_a? ( Array )
71+ user_provided_value . each do |new_prop |
72+ configuration = do_merge ( configuration , new_prop , should_log )
73+ end
74+ else
75+ fail "User configuration value is not valid: #{ user_provided_value } "
76+ end
77+ logger . debug { "Configuration from #{ file } modified with: #{ user_provided } " } if should_log
78+ end
79+
80+ configuration
81+ end
82+
7183 def do_merge ( hash_v1 , hash_v2 , should_log )
7284 hash_v2 . each do |key , value |
7385 if hash_v1 . key? key
0 commit comments