really-confy 0.2.1 → 0.2.2

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 +5 -5
  2. data/lib/really_confy.rb +26 -3
  3. metadata +2 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d8b66a182e1d7c887d75d5f344831351c1735eb0
4
- data.tar.gz: cf7768c87280384cd1e23ce19956420f97e3f77a
2
+ SHA256:
3
+ metadata.gz: fe43d28fb270524f64d23ada64d2a054d83e37ea05e94499f5406fea12271687
4
+ data.tar.gz: 6d91c998d8025c14777f9a2f1adf69e7f3d47a8590f39ce7510f031ed3917de0
5
5
  SHA512:
6
- metadata.gz: cb7418f5d8c25342d2e28d6f30e96212fea238692d9c8f525bcc5358986d4e19119d10d27434706299255f5b21127d6363a6be3e8d746905cf61a1fd3fa106ee
7
- data.tar.gz: 6aa643bb79169707716d299dd983c31358a8d64b304f6e2bd7cae37164588a5988545482baaea65d5b9c7c2c335bcecb447a99abb591aabd2bc22d5195f310a7
6
+ metadata.gz: 677a176c7db12f371b9e5dbb13d532de8b5260135dae1bf10269261cf927ab5282d9d66dfccf12f555b4599a4e5d74b8918d01b0d6da21da8d8d139669fa7548
7
+ data.tar.gz: 16d4463184283d057fe836f861d0eb85f2a89105cdffde3e2f3cf52b96ab0c7457a390da3a985a019bff964a2367b9c800e1502f7ae9353fe24241205a123846
@@ -86,9 +86,9 @@ class ReallyConfy
86
86
  end
87
87
 
88
88
  env_configs = multi_env_configs.map{|multi_env_config|
89
- multi_env_config.fetch('DEFAULTS', {}).deep_merge multi_env_config.fetch(env, {})
89
+ deep_merge multi_env_config.fetch('DEFAULTS', empty_config), multi_env_config.fetch(env, empty_config)
90
90
  }
91
- merged_config = env_configs.reduce{|merged_config, config| merged_config.deep_merge(config) }
91
+ merged_config = env_configs.reduce{|merged_config, config| deep_merge(merged_config, config) }
92
92
 
93
93
  merged_config['env'] ||= env
94
94
 
@@ -118,13 +118,17 @@ class ReallyConfy
118
118
  raise e
119
119
  end
120
120
 
121
+ def empty_config
122
+ ReallyConfy::Config.new {}
123
+ end
124
+
121
125
  def load_config_file(file)
122
126
  full_path = full_path_to_config_file(file)
123
127
 
124
128
  if File.exists? full_path
125
129
  multi_env_config = (ReallyConfy::Config.load full_path)
126
130
  else
127
- multi_env_config = ReallyConfy::Config.new {}
131
+ multi_env_config = empty_config
128
132
  end
129
133
 
130
134
  multi_env_config
@@ -132,6 +136,25 @@ class ReallyConfy
132
136
 
133
137
  private
134
138
 
139
+ def deep_merge(base_hash, other_hash, &block)
140
+ base_hash = base_hash.dup
141
+ other_hash.each_pair do |current_key, other_value|
142
+ this_value = base_hash[current_key]
143
+
144
+ base_hash[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
145
+ deep_merge(this_value, other_value, &block)
146
+ else
147
+ if block_given? && base_hash.key?(current_key)
148
+ block.call(current_key, this_value, other_value)
149
+ else
150
+ other_value
151
+ end
152
+ end
153
+ end
154
+
155
+ base_hash
156
+ end
157
+
135
158
  def full_path_to_config_file(file)
136
159
  File.absolute_path(relative_path_to_config_file(file))
137
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: really-confy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zukowski
@@ -65,10 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  requirements: []
68
- rubyforge_project:
69
- rubygems_version: 2.2.2
68
+ rubygems_version: 3.0.3
70
69
  signing_key:
71
70
  specification_version: 4
72
71
  summary: Simple YAML configuration loader
73
72
  test_files: []
74
- has_rdoc: