config_default 0.6.0 → 0.6.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/config_default/struct.rb +6 -1
- data/lib/config_default/version.rb +1 -1
- data/lib/config_default.rb +12 -14
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52f0736f97782e152e389cbd1be631230bc8cafd7c2271c1499cd61234ad8c60
|
|
4
|
+
data.tar.gz: 34ff7b8184c350f8cb9d2ea3412a6032206d44dabedfd42fd3d5c8f2401fe985
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9df4052f0df98a43e498dd4711f83e6521f4b857f103af47018d48d8bef1c890f0ae4537cc87fe38d243f07aecf1e8f7818dc585fd08e742564f5e555112ce6b
|
|
7
|
+
data.tar.gz: 0b15006d8debe471b852a12d4228864fbd869455866fda3a735a11ce2c588c222bef179ae311afbae328060a1ff414ab83ffaffbde39cfd16e6609d4de690396
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class ConfigDefault::Struct
|
|
4
|
-
RESERVED_METHODS = %i[method_missing respond_to_missing? to_hash].freeze
|
|
4
|
+
RESERVED_METHODS = %i[method_missing respond_to_missing? inspect to_hash to_s].freeze
|
|
5
5
|
|
|
6
6
|
def initialize(attributes, recursive: false, allow_nil: false)
|
|
7
7
|
@attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
|
|
@@ -27,6 +27,11 @@ class ConfigDefault::Struct
|
|
|
27
27
|
true
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
def inspect
|
|
31
|
+
"#<ConfigDefault::Struct @attributes=#{to_hash} " \
|
|
32
|
+
"@recursive=#{@recursive} @allow_nil=#{@allow_nil}>"
|
|
33
|
+
end
|
|
34
|
+
|
|
30
35
|
def to_hash
|
|
31
36
|
dup = @attributes.dup
|
|
32
37
|
|
data/lib/config_default.rb
CHANGED
|
@@ -26,15 +26,22 @@ module ConfigDefault
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def hash(name, key: Rails.env, symbolize_keys: false, deep_symbolize_keys: false)
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
path1 = File.join(config.config_path, "#{name}.#{config.postfix}.yml")
|
|
30
|
+
path2 = File.join(config.config_path, "#{name}.yml")
|
|
31
|
+
|
|
32
|
+
unless File.exist?(path1) || File.exist?(path2)
|
|
33
|
+
raise Errno::ENOENT.new("#{path1} && #{path2}")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
config1 = File.exist?(path1) ? ActiveSupport::ConfigurationFile.parse(path1) : {}
|
|
37
|
+
config2 = File.exist?(path2) ? ActiveSupport::ConfigurationFile.parse(path2) : {}
|
|
31
38
|
|
|
32
39
|
if key
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
config1 = config1[key] || {}
|
|
41
|
+
config2 = config2[key] || {}
|
|
35
42
|
end
|
|
36
43
|
|
|
37
|
-
data =
|
|
44
|
+
data = config1.deep_merge(config2)
|
|
38
45
|
|
|
39
46
|
if deep_symbolize_keys
|
|
40
47
|
data.deep_symbolize_keys
|
|
@@ -51,13 +58,4 @@ module ConfigDefault
|
|
|
51
58
|
struct.class_eval(&block) if block
|
|
52
59
|
struct
|
|
53
60
|
end
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
def read_file(name)
|
|
58
|
-
file_name = File.join(config.config_path, "#{name}.yml")
|
|
59
|
-
ActiveSupport::ConfigurationFile.parse(file_name)
|
|
60
|
-
rescue Errno::ENOENT
|
|
61
|
-
{}
|
|
62
|
-
end
|
|
63
61
|
end
|