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 +4 -4
- data/lib/conf_loader.rb +10 -2
- data/lib/conf_loader/version.rb +1 -1
- data/spec/integration/conf_loader_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a10bbb4fbd9c6709fadc4ea0f27ac86d2517a90
|
4
|
+
data.tar.gz: 1caf978351e72410f0c442ba1132c86bc0dffa12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
23
|
-
|
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
|
data/lib/conf_loader/version.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: symbolizer
|