rock_config 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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 :elastic_search
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 :elastic_search, :production
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:
@@ -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)
@@ -0,0 +1,6 @@
1
+ module RockConfig
2
+ class Error < StandardError; end
3
+ class ConfigLoadError < Error; end
4
+ class ConfigNotFoundError < Error; end
5
+ class EnvironmentNotFoundError < Error; end
6
+ end
@@ -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 environment
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
 
@@ -13,7 +13,7 @@ module RockConfig
13
13
  end
14
14
  end
15
15
 
16
- raise ConfigNotFound, "Config not found"
16
+ raise ConfigNotFoundError, "Config not found"
17
17
  end
18
18
  end
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module RockConfig
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -26,6 +26,8 @@ module RockConfig
26
26
 
27
27
  def load_yaml_from(path)
28
28
  YAML.load_file(path)
29
+ rescue Psych::SyntaxError => e
30
+ raise ConfigLoadError, e.message
29
31
  end
30
32
  end
31
33
  end
@@ -18,14 +18,18 @@ module RockConfig
18
18
  manager_result.should eq("yay")
19
19
  end
20
20
 
21
- it "returns nul if config not found" do
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") { nil }
27
+ scanner.should_receive(:find).with("sample") { result }
25
28
 
26
29
  manager = Manager.new(configuration, scanner)
27
-
28
- manager.fetch("sample", "development").should be_nil
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
@@ -15,7 +15,7 @@ module RockConfig
15
15
  it "finds nothing when the target doesnt exist" do
16
16
  expect do
17
17
  scanner.find("database")
18
- end.to raise_error(ConfigNotFound)
18
+ end.to raise_error(ConfigNotFoundError)
19
19
  end
20
20
 
21
21
  it "scans additional directories" do
@@ -17,7 +17,7 @@ module RockConfig
17
17
 
18
18
  expect do
19
19
  config = loader.find_at(directory, "database_invalid")
20
- end.to raise_error(Psych::SyntaxError)
20
+ end.to raise_error(RockConfig::ConfigLoadError)
21
21
  end
22
22
  end
23
23
  end
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.1
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-02 00:00:00.000000000 Z
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: