config-hash 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/config-hash.gemspec +1 -1
- data/lib/config-hash.rb +23 -29
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18cc65d997214d22026cd64bd4a4a648e943d0f5aabe62e25633d583e8c1426c
|
4
|
+
data.tar.gz: 9b8de42e1c7428a97aae9e82338dd0e6dd00c23995d0078ca5be05d6d4d87213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9e93f97ad627f5ba663d444c35cf3266e0351d1fb5dedf01fe26912e26d0773368d80f6677f474e69905930f1f6d65fe978579840b2f0dbb20f566ada7157f
|
7
|
+
data.tar.gz: d612503adbdc102de8a4a81e2d60c45dca4ab8f21c997384b65263f0dee9cd7e4894d93f3dcbe9feb2f0ae5c6116c0906e44e962e42391cee364c112a3721245
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5
|
1
|
+
2.6.5
|
data/config-hash.gemspec
CHANGED
data/lib/config-hash.rb
CHANGED
@@ -3,32 +3,25 @@ class Hash
|
|
3
3
|
def +@; ConfigHash[self]; end
|
4
4
|
end
|
5
5
|
|
6
|
-
class Array
|
7
|
-
def keys
|
8
|
-
+Hash[zip]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
6
|
class NormalHash < Hash
|
13
7
|
end
|
14
8
|
|
15
9
|
class ConfigHash < Hash
|
16
10
|
SEPARATORS ||= %r|[./]|
|
17
11
|
|
18
|
-
# remove likely collisions
|
19
|
-
undef_method :zip
|
20
|
-
|
21
12
|
def self.[](hash=nil)
|
22
13
|
new(hash)
|
23
14
|
end
|
24
15
|
|
25
|
-
def self.load(path="config.rb",
|
16
|
+
def self.load(path="config.rb", list=nil, name: "config")
|
26
17
|
path = File.expand_path(path)
|
27
|
-
eval
|
28
|
-
#{
|
29
|
-
#{IO.read(path, encoding: 'utf-8') if File.
|
30
|
-
#{
|
18
|
+
data = eval <<~"end", binding, path, 0
|
19
|
+
#{name} ||= new
|
20
|
+
#{IO.read(path, encoding: 'utf-8') if File.readable?(path)}
|
21
|
+
#{name}
|
31
22
|
end
|
23
|
+
data.load(*list) if list && !list.empty?
|
24
|
+
data
|
32
25
|
end
|
33
26
|
|
34
27
|
def initialize(hash=nil)
|
@@ -36,21 +29,21 @@ class ConfigHash < Hash
|
|
36
29
|
update(hash) if hash
|
37
30
|
end
|
38
31
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
def load(*list)
|
33
|
+
[list].each do |root, glob|
|
34
|
+
root = File.expand_path(root)
|
35
|
+
pref = root.size + 1
|
36
|
+
full = File.join([root, glob].compact)
|
37
|
+
list = Dir[full].sort {|a,b| [a.count('/'), a] <=> [b.count('/'), b]}
|
38
|
+
list.each do |path|
|
39
|
+
info = File.dirname(path[pref...] || '')
|
40
|
+
data = ConfigHash.load(path)
|
41
|
+
info == '.' ? update(data) : (self[info] = data)
|
42
|
+
end
|
46
43
|
end
|
47
44
|
self
|
48
45
|
end
|
49
46
|
|
50
|
-
def zip!(*args)
|
51
|
-
+Hash[keys.zip(*args)]
|
52
|
-
end
|
53
|
-
|
54
47
|
def key?(key)
|
55
48
|
super(key.to_s)
|
56
49
|
end
|
@@ -88,15 +81,16 @@ class ConfigHash < Hash
|
|
88
81
|
end
|
89
82
|
end
|
90
83
|
|
91
|
-
|
92
|
-
|
93
|
-
def update(hash)
|
84
|
+
def update(hash, nuke=false)
|
94
85
|
raise ArgumentError unless Hash === hash
|
86
|
+
clear if nuke
|
95
87
|
hash.each {|key, val| self[key] = val}
|
96
88
|
self
|
97
89
|
end
|
98
90
|
|
99
|
-
|
91
|
+
def update!(hash)
|
92
|
+
update(hash, true)
|
93
|
+
end
|
100
94
|
|
101
95
|
def to_hash
|
102
96
|
Hash[self]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config-hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem makes it easy to work with configuration data.
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -26,7 +26,7 @@ homepage: https://github.com/shreeve/config-hash
|
|
26
26
|
licenses:
|
27
27
|
- MIT
|
28
28
|
metadata: {}
|
29
|
-
post_install_message:
|
29
|
+
post_install_message:
|
30
30
|
rdoc_options: []
|
31
31
|
require_paths:
|
32
32
|
- lib
|
@@ -41,9 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
|
-
|
45
|
-
|
46
|
-
signing_key:
|
44
|
+
rubygems_version: 3.2.16
|
45
|
+
signing_key:
|
47
46
|
specification_version: 4
|
48
47
|
summary: A safe, homoiconic, Ruby hash supporting dot notation
|
49
48
|
test_files: []
|