figly 1.0.3 → 1.0.4
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/lib/figly.rb +13 -1
- data/lib/figly/version.rb +1 -1
- data/spec/figly_spec.rb +6 -0
- 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: 65ac42decd3b9d8da0ffa6a4d00401300a0e83dc
|
4
|
+
data.tar.gz: d257ea30a2c4242b96d4e3213a4aab91540e213f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 170370e713d00bfc38576067ce7ae0b6b4d82bea2febbebb1224c6ecf220aefeef1d88894a5130c18b4344ae96e07276d68d5640134c1cfa52946c87dd2e64b4
|
7
|
+
data.tar.gz: 7e04253fef6b344ad1c7a36d54c33344835f14c831033b0fabf18f24a904e69bd4b5174483bdef7ce1de1658269abe028ec17e3b0b59d28b9d0c436ad54e3380
|
data/lib/figly.rb
CHANGED
@@ -5,6 +5,7 @@ module Figly
|
|
5
5
|
class ParserError < StandardError; end
|
6
6
|
class UnsupportedFormatError < StandardError; end
|
7
7
|
class ConfigNotFoundError < StandardError; end
|
8
|
+
class ConfigNotLoaded < StandardError; end
|
8
9
|
|
9
10
|
def self.load_file(path)
|
10
11
|
raise ConfigNotFoundError, "File does not exist: #{path}" unless File.exists?(path)
|
@@ -47,7 +48,7 @@ module Figly
|
|
47
48
|
end
|
48
49
|
|
49
50
|
# Here we merge config files if there are multiple load calls
|
50
|
-
if
|
51
|
+
if _config_loaded?
|
51
52
|
_deep_merge(@@data, data)
|
52
53
|
else
|
53
54
|
@@data = data
|
@@ -60,6 +61,7 @@ module Figly
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def self.data
|
64
|
+
_ensure_loaded!
|
63
65
|
@@data
|
64
66
|
end
|
65
67
|
|
@@ -67,4 +69,14 @@ module Figly
|
|
67
69
|
merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
|
68
70
|
first.merge!(second, &merger)
|
69
71
|
end
|
72
|
+
|
73
|
+
def self._ensure_loaded!
|
74
|
+
unless _config_loaded?
|
75
|
+
raise ConfigNotLoaded, "You must first load the config before attempting to access it"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self._config_loaded?
|
80
|
+
defined?(@@data) && @@data
|
81
|
+
end
|
70
82
|
end
|
data/lib/figly/version.rb
CHANGED
data/spec/figly_spec.rb
CHANGED
@@ -59,6 +59,8 @@ describe Figly do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'errors' do
|
62
|
+
after { Figly.clean }
|
63
|
+
|
62
64
|
context 'ParserError' do
|
63
65
|
it 'should error on bad.yml' do
|
64
66
|
expect{Figly.load_file('spec/support/bad.yml')}.to raise_error(Figly::ParserError)
|
@@ -81,5 +83,9 @@ describe Figly do
|
|
81
83
|
it 'should raise an error on an unsupported config file format' do
|
82
84
|
expect{ Figly.load_file("spec/support/config.ini") }.to raise_error(Figly::UnsupportedFormatError)
|
83
85
|
end
|
86
|
+
|
87
|
+
it 'should raise an exception if data is trying to be accessed before Figly has been loaded' do
|
88
|
+
expect{ Figly::Settings.a.b }.to raise_error(Figly::ConfigNotLoaded)
|
89
|
+
end
|
84
90
|
end
|
85
91
|
end
|