conf_loader 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25492b776e0ca7cfb529e5e4a7ba8a6cd6bbf4b9
4
- data.tar.gz: 8007d6e02988736c9523ae27544b3f51919e945f
3
+ metadata.gz: 0a10bbb4fbd9c6709fadc4ea0f27ac86d2517a90
4
+ data.tar.gz: 1caf978351e72410f0c442ba1132c86bc0dffa12
5
5
  SHA512:
6
- metadata.gz: de1cbfc5185d4c508e05626893e13aaefc56013caadcab778bc6727af5620f05d5fcc5f797057fcd769ffdc9603b9e23f30dd9796747df3aa594c0e04de3e2bf
7
- data.tar.gz: f44ba29df38814cd83e0b18258d3c3006c2da6cc5cb607e5f12d1231a5d7b16ae42810dd59edb5d4923875a7cc7edf88db0ae59b9a6526a0551d3eb0897be98a
6
+ metadata.gz: ec0620fa2f0c7e6645dd47ef0c9b9dc6d6e28ebcf6d00848b0d901ede03afe9a6e4a31a81a6ef8d8bdcb51bd0f21ba5ce6dbdf3d31b3e9969d0afa48a78d5335
7
+ data.tar.gz: fbbb5f5c701717c369dd5a37839310a92316b94f42bb2fe25c14d2048ec2dc15685f9838f62423dd10d19d9f6d4057c684891fc78490637a2f99aa6249301b47
data/lib/conf_loader.rb CHANGED
@@ -5,6 +5,8 @@ require 'erb'
5
5
  # Helps to load conf files in salemove ecosystem
6
6
  #
7
7
  class ConfLoader
8
+ EnvironmentNotFoundError = Class.new(KeyError)
9
+
8
10
  # Load given conf file
9
11
  #
10
12
  # @path [String] path
@@ -19,7 +21,13 @@ class ConfLoader
19
21
  def self.load(path, env)
20
22
  template = ERB.new File.new(path).read
21
23
  environments = YAML.load template.result(binding)
22
- hash = environments[env]
23
- Symbolizer.symbolize(hash)
24
+
25
+ if environments.has_key?(env)
26
+ hash = environments[env]
27
+ Symbolizer.symbolize(hash)
28
+ else
29
+ raise EnvironmentNotFoundError,
30
+ "Configuration for `#{env}` not found at path #{path}"
31
+ end
24
32
  end
25
33
  end
@@ -1,3 +1,3 @@
1
1
  class ConfLoader
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -3,6 +3,14 @@ require 'spec_helper'
3
3
  describe ConfLoader do
4
4
  let(:path) { File.dirname(__FILE__) + '/../fixtures/simple.yml' }
5
5
 
6
+ context 'when environment not defined' do
7
+ let(:conf) { described_class.load(path, 'office') }
8
+
9
+ it 'raises a key not found error' do
10
+ expect { conf }.to raise_error(described_class::EnvironmentNotFoundError, /Configuration for \`office\` not found at path .*/)
11
+ end
12
+ end
13
+
6
14
  context 'conf loaded with production deployment setting' do
7
15
 
8
16
  let(:conf) { described_class.load(path, 'production') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conf_loader
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
  - Indrek Juhkam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: symbolizer