collapsium-config 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/collapsium-config.rb +8 -5
- data/lib/collapsium-config/version.rb +1 -1
- data/spec/module_spec.rb +26 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b003113648d35417f65b7f142c1e1957df44390e
|
4
|
+
data.tar.gz: 4c6ddaf1aafe5804b918877b5663169a85206afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07fd37c0e483fb12ecbd24924a27af10a49f4c07a8ffaff28bf9555b983b26377fdd5ab7b3a29b19ff0687d95a64c746db21df980838b9e87aed4be2a551dfa9
|
7
|
+
data.tar.gz: a0df3d326c1a71bd9001517b5f801fd9d7aab93054dd105d42a4604382881eb8b790c452b7ab2d7245534bb93ce19dc78460c74695eb665fd41cd787cfd3dfed
|
data/Gemfile.lock
CHANGED
data/lib/collapsium-config.rb
CHANGED
@@ -31,21 +31,24 @@ module Collapsium
|
|
31
31
|
def config_file
|
32
32
|
return @config_file || DEFAULT_CONFIG_PATH
|
33
33
|
end
|
34
|
+
|
35
|
+
# @api private
|
36
|
+
attr_accessor :config
|
34
37
|
end # module ClassMethods
|
35
38
|
extend ClassMethods
|
36
39
|
|
37
40
|
##
|
38
|
-
# Access the global configuration
|
41
|
+
# Access the global configuration.
|
39
42
|
def config
|
40
|
-
if
|
43
|
+
if Config.config.nil? or Config.config.empty?
|
41
44
|
begin
|
42
|
-
|
45
|
+
Config.config = Configuration.load_config(Config.config_file)
|
43
46
|
rescue Errno::ENOENT
|
44
|
-
|
47
|
+
Config.config = {}
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
|
-
return
|
51
|
+
return Config.config
|
49
52
|
end
|
50
53
|
end # module Config
|
51
54
|
end # module Collapsium
|
data/spec/module_spec.rb
CHANGED
@@ -9,17 +9,35 @@ describe Collapsium::Config do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "fails to load configuration from the default path (it does not exist)" do
|
12
|
+
expect(Collapsium::Config.config_file).to eql \
|
13
|
+
Collapsium::Config::DEFAULT_CONFIG_PATH
|
12
14
|
expect(config.empty?).to be_truthy
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
describe "providing a config file path" do
|
18
|
+
before :each do
|
19
|
+
Collapsium::Config.config_file = Collapsium::Config::DEFAULT_CONFIG_PATH
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails to load configuration files of unrecognized formats" do
|
23
|
+
Collapsium::Config.config_file = File.join(@data_path, 'foo.bar')
|
24
|
+
expect { config.empty? }.to raise_error(ArgumentError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "loads configuration from an existing path" do
|
28
|
+
Collapsium::Config.config_file = File.join(@data_path, 'global.yml')
|
29
|
+
expect { config.empty? }.not_to raise_error(ArgumentError)
|
30
|
+
expect(config.empty?).to be_falsy
|
31
|
+
end
|
32
|
+
|
33
|
+
it "does not load the same configuration twice" do
|
34
|
+
Collapsium::Config.config_file = File.join(@data_path, 'global.yml')
|
35
|
+
cfg1 = config
|
36
|
+
|
37
|
+
Collapsium::Config.config_file = File.join(@data_path, 'global.yml')
|
38
|
+
cfg2 = config
|
19
39
|
|
20
|
-
|
21
|
-
|
22
|
-
expect { config.empty? }.not_to raise_error(ArgumentError)
|
23
|
-
expect(config.empty?).to be_falsy
|
40
|
+
expect(cfg1.object_id).to eql cfg2.object_id
|
41
|
+
end
|
24
42
|
end
|
25
43
|
end
|