toolrack 0.12.0 → 0.13.0
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/toolrack/condition_utils.rb +6 -0
- data/lib/toolrack/hash_config.rb +115 -0
- data/lib/toolrack/version.rb +1 -1
- data/lib/toolrack.rb +2 -2
- metadata +3 -3
- data/lib/toolrack/mixin_helper.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8dd55a26c516a19fa866167542d1654ad82e8bd004eb099898030ee72b3128f
|
4
|
+
data.tar.gz: 28e576da345ff8e9d43e4e890cbb1ce66b7d896740a22e62693b7b1e8f17cbb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23af16b224d1fed00c2cf4b9e9649ec7c3c6438ab2309f193a61f15eed06c556a6176b94bcb87bbadf32d81f3cd9008d43610d896c05a2f0ad8dccc41668a589
|
7
|
+
data.tar.gz: 87e16f2c2a2761c229bbe979960b2bf58c05e5712d351ad2b148569f426e6a628720ee5a39de647d428ab51bfceb249ca5ceb7a1f8c1aaa002b16210973b7775
|
@@ -48,6 +48,12 @@ module Antrapol
|
|
48
48
|
end
|
49
49
|
alias_method :is_str_bool?, :is_string_boolean?
|
50
50
|
|
51
|
+
def self.included(klass)
|
52
|
+
klass.class_eval <<-END
|
53
|
+
extend Antrapol::ToolRack::ConditionUtils
|
54
|
+
END
|
55
|
+
end
|
56
|
+
|
51
57
|
end # ConditionUtils
|
52
58
|
end # MyToolRack
|
53
59
|
end # Antrapol
|
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
module Antrapol
|
5
|
+
module ToolRack
|
6
|
+
module HashConfig
|
7
|
+
include ConditionUtils
|
8
|
+
|
9
|
+
class HashConfigError < StandardError; end
|
10
|
+
|
11
|
+
def hcdeli=(deli)
|
12
|
+
@hcdeli = deli
|
13
|
+
end
|
14
|
+
def hcdeli
|
15
|
+
if is_empty?(@hcdeli)
|
16
|
+
@hcdeli = "."
|
17
|
+
end
|
18
|
+
@hcdeli
|
19
|
+
end
|
20
|
+
|
21
|
+
def hcset(key, value)
|
22
|
+
raise HashConfigError, "Nil key is not supported" if is_empty?(key)
|
23
|
+
|
24
|
+
keys = transform_keys(key)
|
25
|
+
root = hcConf
|
26
|
+
keys.each do |k|
|
27
|
+
if root.is_a?(Hash)
|
28
|
+
if not root.keys.include?(k)
|
29
|
+
root[k] = { }
|
30
|
+
end
|
31
|
+
|
32
|
+
if k == keys[-1]
|
33
|
+
root[k] = value
|
34
|
+
else
|
35
|
+
root = root[k]
|
36
|
+
end
|
37
|
+
|
38
|
+
else
|
39
|
+
raise HashConfigError, "The key '#{k}' currently not tie to a hash. It is an #{root.class} object of value '#{root}'. There is no way to add another value to key '#{key}'. Try to change it to Hash object instead."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
root
|
43
|
+
end
|
44
|
+
|
45
|
+
def hcget(key, defVal = nil)
|
46
|
+
if key.nil?
|
47
|
+
return nil
|
48
|
+
else
|
49
|
+
keys = transform_keys(key)
|
50
|
+
node = hcConf
|
51
|
+
keys.each do |k|
|
52
|
+
if node.keys.include?(k)
|
53
|
+
node = node[k]
|
54
|
+
else
|
55
|
+
node = nil
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
node.nil? ? defVal : node
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def hcinclude?(key)
|
64
|
+
if key.nil?
|
65
|
+
return false
|
66
|
+
else
|
67
|
+
keys = transform_keys(key)
|
68
|
+
node = hcConf
|
69
|
+
keys.each do |k|
|
70
|
+
if node.is_a?(Hash)
|
71
|
+
if node.keys.include?(k)
|
72
|
+
node = node[k]
|
73
|
+
else
|
74
|
+
node = nil
|
75
|
+
break
|
76
|
+
end
|
77
|
+
else
|
78
|
+
node = nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
not node.nil?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def split_key(key)
|
87
|
+
if not_empty?(key)
|
88
|
+
key.split(hcdeli)
|
89
|
+
else
|
90
|
+
[key]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def transform_keys(key)
|
95
|
+
case key
|
96
|
+
when String
|
97
|
+
split_key(key)
|
98
|
+
when Array
|
99
|
+
key
|
100
|
+
else
|
101
|
+
[key]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def hcConf
|
106
|
+
if @hcConf.nil?
|
107
|
+
@hcConf = { }
|
108
|
+
end
|
109
|
+
@hcConf
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
data/lib/toolrack/version.rb
CHANGED
data/lib/toolrack.rb
CHANGED
@@ -12,7 +12,7 @@ require_relative 'toolrack/process_utils'
|
|
12
12
|
require_relative 'toolrack/runtime_utils'
|
13
13
|
require_relative 'toolrack/data_conversion_utils'
|
14
14
|
require_relative 'toolrack/password_utils'
|
15
|
-
require_relative 'toolrack/
|
15
|
+
require_relative 'toolrack/hash_config'
|
16
16
|
|
17
17
|
module Antrapol
|
18
18
|
module ToolRack
|
@@ -44,5 +44,5 @@ TR::ExpUtils = ToolRack::ExpUtils
|
|
44
44
|
ToolRack::RTUtils = ToolRack::RuntimeUtils
|
45
45
|
TR::RTUtils = ToolRack::RTUtils
|
46
46
|
|
47
|
-
TR::
|
47
|
+
TR::HashConfig = ToolRack::HashConfig
|
48
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toolrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tlogger
|
@@ -87,7 +87,7 @@ files:
|
|
87
87
|
- lib/toolrack/data_conversion_utils.rb
|
88
88
|
- lib/toolrack/exception_utils.rb
|
89
89
|
- lib/toolrack/global.rb
|
90
|
-
- lib/toolrack/
|
90
|
+
- lib/toolrack/hash_config.rb
|
91
91
|
- lib/toolrack/password_utils.rb
|
92
92
|
- lib/toolrack/process_utils.rb
|
93
93
|
- lib/toolrack/runtime_utils.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Antrapol
|
4
|
-
module ToolRack
|
5
|
-
module MixinHelper
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def mixin(cls)
|
9
|
-
self.class_eval "include #{cls}"
|
10
|
-
end
|
11
|
-
|
12
|
-
def class_method(&block)
|
13
|
-
class_eval <<-END
|
14
|
-
module ClassMethods
|
15
|
-
end
|
16
|
-
END
|
17
|
-
ClassMethods.class_eval(&block)
|
18
|
-
end
|
19
|
-
end # module ClassMethods
|
20
|
-
|
21
|
-
def self.included(klass)
|
22
|
-
klass.extend(ClassMethods)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|