complex_config 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/complex_config.gemspec +2 -2
- data/lib/complex_config/provider.rb +23 -14
- data/lib/complex_config/settings.rb +7 -0
- data/lib/complex_config/version.rb +1 -1
- 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: f00c1e6723f460cadcdb4e628f8770101db83723
|
4
|
+
data.tar.gz: 133f3d106b681fae18fa001f9bbf4386770d6ebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 703e77e3fd176f17a40f1840941c19e74af32411ed2fb518193fa76b495a9977212fc6eab567a4d93a4a6dc1478bc5c2af12194a333fe702acac95474051104a
|
7
|
+
data.tar.gz: b27c4493969d30fa486dd87c2237f5c6f0f3e98cb197e5def3a18928126c05b1857231b019875d7e307ebbc6b3329be9930a9a693d096d3eed2a9916c25dc7dc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.11.
|
1
|
+
0.11.1
|
data/complex_config.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: complex_config 0.11.
|
2
|
+
# stub: complex_config 0.11.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "complex_config".freeze
|
6
|
-
s.version = "0.11.
|
6
|
+
s.version = "0.11.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
@@ -57,22 +57,31 @@ class ComplexConfig::Provider
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def config(pathname, name = nil)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
datas = []
|
61
|
+
if File.exist?(pathname)
|
62
|
+
datas << IO.binread(pathname)
|
63
|
+
end
|
64
|
+
if enc_pathname = pathname.to_s + '.enc' and File.exist?(enc_pathname)
|
65
|
+
key = key(pathname)
|
66
|
+
text = IO.binread(enc_pathname)
|
67
|
+
datas << ComplexConfig::Encryption.new(key).decrypt(text)
|
68
|
+
end
|
69
|
+
datas.empty? and raise ComplexConfig::ConfigurationFileMissing,
|
70
|
+
"configuration file #{pathname.inspect} is missing"
|
71
|
+
results = datas.map { |d| evaluate(pathname, d) }
|
72
|
+
hashes = results.map { |r| ::YAML.load(r, pathname) }
|
73
|
+
settings = ComplexConfig::Settings.build(name, hashes.first)
|
74
|
+
hashes[1..-1]&.each { |h| settings.attributes_update(h) }
|
75
|
+
if shared = settings.shared?
|
76
|
+
shared = shared.to_h
|
77
|
+
settings.each do |key, value|
|
78
|
+
if value.is_a? ComplexConfig::Settings
|
79
|
+
value.attributes_update(shared)
|
80
|
+
end
|
68
81
|
end
|
69
|
-
result = evaluate(pathname, data)
|
70
|
-
hash = ::YAML.load(result, pathname)
|
71
|
-
ComplexConfig::Settings.build(name, hash).tap do |settings|
|
72
|
-
deep_freeze? and settings.deep_freeze
|
73
82
|
end
|
74
|
-
|
75
|
-
|
83
|
+
deep_freeze? and settings.deep_freeze
|
84
|
+
settings
|
76
85
|
rescue ::Psych::SyntaxError => e
|
77
86
|
raise ComplexConfig::ComplexConfigError.wrap(:ConfigurationSyntaxError, e)
|
78
87
|
end
|
@@ -69,6 +69,13 @@ class ComplexConfig::Settings < BasicObject
|
|
69
69
|
@table.values
|
70
70
|
end
|
71
71
|
|
72
|
+
def attributes_update(other)
|
73
|
+
unless other.is_a? self.class
|
74
|
+
other = self.class.from_hash(other)
|
75
|
+
end
|
76
|
+
@table.update(other.table)
|
77
|
+
end
|
78
|
+
|
72
79
|
def replace_attributes(hash)
|
73
80
|
@table = self.class.from_hash(hash).table
|
74
81
|
self
|