rock_config 0.0.1 → 0.0.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.
- data/README.md +2 -2
- data/lib/rock_config.rb +1 -2
- data/lib/rock_config/errors.rb +6 -0
- data/lib/rock_config/manager.rb +6 -1
- data/lib/rock_config/scanner.rb +1 -1
- data/lib/rock_config/version.rb +1 -1
- data/lib/rock_config/yaml_loader.rb +2 -0
- data/spec/manager_spec.rb +8 -4
- data/spec/scanner_spec.rb +1 -1
- data/spec/yaml_loader_spec.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -30,13 +30,13 @@ Given the file elastic_search.yml:
|
|
30
30
|
|
31
31
|
RockConfig allows you to read these settings with an API like this:
|
32
32
|
|
33
|
-
elastic_config = RockConfig.for
|
33
|
+
elastic_config = RockConfig.for "elastic_search"
|
34
34
|
elastic_config.host # > 127.0.0.1
|
35
35
|
|
36
36
|
RockConfig automatically chooses the current application environment. You select the environment yourself
|
37
37
|
with:
|
38
38
|
|
39
|
-
RockConfig.for
|
39
|
+
RockConfig.for "elastic_search", "production"
|
40
40
|
|
41
41
|
RockConfig scans predefined directories for config files. By default, it tries to scan directory
|
42
42
|
`config` in the project root. You can add more directories:
|
data/lib/rock_config.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "rock_config/version"
|
2
|
+
require "rock_config/errors"
|
2
3
|
require "rock_config/environment_detector"
|
3
4
|
require "rock_config/configuration"
|
4
5
|
require "rock_config/manager"
|
@@ -7,8 +8,6 @@ require "rock_config/yaml_loader"
|
|
7
8
|
require "rock_config/config"
|
8
9
|
|
9
10
|
module RockConfig
|
10
|
-
class ConfigNotFound < Exception; end
|
11
|
-
|
12
11
|
class << self
|
13
12
|
def for(config_name, environment = detect_environment)
|
14
13
|
manager.fetch(config_name, environment)
|
data/lib/rock_config/manager.rb
CHANGED
@@ -7,7 +7,12 @@ module RockConfig
|
|
7
7
|
|
8
8
|
def fetch(config_name, environment)
|
9
9
|
if config = @configs[config_name]
|
10
|
-
config.send
|
10
|
+
if config_for_environment = config.send(environment)
|
11
|
+
return config_for_environment
|
12
|
+
else
|
13
|
+
raise EnvironmentNotFoundError,
|
14
|
+
'Environment "%s" not found' % environment
|
15
|
+
end
|
11
16
|
end
|
12
17
|
end
|
13
18
|
|
data/lib/rock_config/scanner.rb
CHANGED
data/lib/rock_config/version.rb
CHANGED
data/spec/manager_spec.rb
CHANGED
@@ -18,14 +18,18 @@ module RockConfig
|
|
18
18
|
manager_result.should eq("yay")
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "raises error if the config doesnt have the environment" do
|
22
|
+
result = mock("Config")
|
23
|
+
result.should_receive(:send).with("development") { nil }
|
24
|
+
|
22
25
|
scanner = mock("Scanner")
|
23
26
|
scanner.should_receive(:new) .with(configuration) { scanner }
|
24
|
-
scanner.should_receive(:find).with("sample") {
|
27
|
+
scanner.should_receive(:find).with("sample") { result }
|
25
28
|
|
26
29
|
manager = Manager.new(configuration, scanner)
|
27
|
-
|
28
|
-
|
30
|
+
expect do
|
31
|
+
manager_result = manager.fetch "sample", "development"
|
32
|
+
end.to raise_error(EnvironmentNotFoundError)
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
data/spec/scanner_spec.rb
CHANGED
data/spec/yaml_loader_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rock_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/rock_config/config.rb
|
77
77
|
- lib/rock_config/configuration.rb
|
78
78
|
- lib/rock_config/environment_detector.rb
|
79
|
+
- lib/rock_config/errors.rb
|
79
80
|
- lib/rock_config/manager.rb
|
80
81
|
- lib/rock_config/scanner.rb
|
81
82
|
- lib/rock_config/version.rb
|
@@ -126,4 +127,3 @@ test_files:
|
|
126
127
|
- spec/scanner_spec.rb
|
127
128
|
- spec/spec_helper.rb
|
128
129
|
- spec/yaml_loader_spec.rb
|
129
|
-
has_rdoc:
|