potrubi 0.0.1 → 0.0.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.
- data/README.md +9 -0
- data/lib/potrubi.rb +9 -0
- data/lib/potrubi/bootstrap.rb +27 -0
- data/lib/potrubi/core.rb +33 -0
- data/lib/potrubi/klass/syntax/braket.rb +197 -0
- data/lib/potrubi/mixin/bootstrap_common.rb +125 -0
- data/lib/potrubi/mixin/configuration.rb +109 -0
- data/lib/potrubi/mixin/contract-recipes.rb +226 -0
- data/lib/potrubi/mixin/contract.rb +105 -0
- data/lib/potrubi/mixin/dynamic-recipes.rb +100 -0
- data/lib/potrubi/mixin/dynamic.rb +315 -0
- data/lib/potrubi/mixin/exception.rb +98 -0
- data/lib/potrubi/mixin/filesys.rb +89 -0
- data/lib/potrubi/mixin/initialize.rb +23 -0
- data/lib/potrubi/mixin/konstant.rb +368 -0
- data/lib/potrubi/mixin/logger.rb +178 -0
- data/lib/potrubi/mixin/pathandnames.rb +226 -0
- data/lib/potrubi/mixin/persistence.rb +192 -0
- data/lib/potrubi/mixin/script.rb +59 -0
- data/lib/potrubi/mixin/text-snippets.rb +182 -0
- data/lib/potrubi/mixin/text-snippets/methods-text-snippets.rb +254 -0
- data/lib/potrubi/mixin/util.rb +53 -0
- data/lib/potrubi/version.rb +1 -1
- metadata +27 -5
@@ -0,0 +1,178 @@
|
|
1
|
+
|
2
|
+
# Common Mixins
|
3
|
+
|
4
|
+
# logger methods
|
5
|
+
|
6
|
+
require "logger"
|
7
|
+
|
8
|
+
module Potrubi
|
9
|
+
module Mixin
|
10
|
+
module Logger
|
11
|
+
|
12
|
+
def logger
|
13
|
+
Logger.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.logger(logrArgs=nil)
|
17
|
+
@logger ||= new_logger(logrArgs)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger(logrArgs=nil)
|
21
|
+
|
22
|
+
logrArgs && (logrArgs.is_a?(Hash) || raise(ArgumentError,"logrArgs >#{logrArgs}< not hash",caller))
|
23
|
+
###log = Log4r.new(STDOUT)
|
24
|
+
|
25
|
+
logrArgsDef = {device: STDOUT, level: ::Logger::DEBUG, datetime_format: "%H:%M:%S"}
|
26
|
+
|
27
|
+
logrArgsUse = logrArgs ? logrArgsDef.merge(logrArgs) : logrArgsDef
|
28
|
+
|
29
|
+
logr = ::Logger.new(logrArgsUse[:device])
|
30
|
+
|
31
|
+
logrArgsUse.delete(:device)
|
32
|
+
|
33
|
+
logrArgsUse.each {|k,v| logr.__send__("#{k}=", v) }
|
34
|
+
|
35
|
+
logr
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
#=begin
|
40
|
+
def logger_enabled?(logrLevel=nil)
|
41
|
+
case logrLevel
|
42
|
+
when Fixnum
|
43
|
+
(@logger_level ||= nil) && @logger_level.is_a?(Fixnum) && (logrLevel <= @logger_level) && logrLevel
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
#=end
|
49
|
+
|
50
|
+
#=begin
|
51
|
+
def logger_fmt(*logrArgs)
|
52
|
+
logrArgs.flatten.compact.join(' ')
|
53
|
+
end
|
54
|
+
alias_method :logger_format_telltales, :logger_fmt
|
55
|
+
alias_method :potrubi_bootstrap_logger_format_telltales, :logger_fmt
|
56
|
+
#=end
|
57
|
+
|
58
|
+
#=begin
|
59
|
+
def logger_message(logEye, *logArgs, &msgBlok)
|
60
|
+
$DEBUG && logger.debug(logEye) { logger_format_telltales(*logArgs) }
|
61
|
+
end
|
62
|
+
#=end
|
63
|
+
|
64
|
+
#=begin
|
65
|
+
def logger_message_beg(logEye, *logArgs, &msgBlok)
|
66
|
+
logger_message(logEye, :BEG, *logArgs, &msgBlok)
|
67
|
+
end
|
68
|
+
#=end
|
69
|
+
#=begin
|
70
|
+
def logger_message_fin(logEye, *logArgs, &msgBlok)
|
71
|
+
logger_message(logEye, :FIN, *logArgs, &msgBlok)
|
72
|
+
end
|
73
|
+
#=end
|
74
|
+
|
75
|
+
#=begin
|
76
|
+
def logger_method_entry(logEye, *a)
|
77
|
+
logger_message(logEye, '==>', *a)
|
78
|
+
end
|
79
|
+
|
80
|
+
def logger_method_exit(logEye, *a)
|
81
|
+
logger_message(logEye, '<==', *a)
|
82
|
+
end
|
83
|
+
|
84
|
+
def logger_method_call(logEye, *a)
|
85
|
+
logger_message(logEye, '<=>', *a)
|
86
|
+
end
|
87
|
+
alias_method :logger_me, :logger_method_entry
|
88
|
+
alias_method :logger_mx, :logger_method_exit
|
89
|
+
alias_method :logger_ca, :logger_method_call
|
90
|
+
#=end
|
91
|
+
|
92
|
+
alias_method :logger_ms, :logger_message
|
93
|
+
alias_method :logger_en?, :logger_enabled?
|
94
|
+
|
95
|
+
alias_method :logger_beg, :logger_message_beg
|
96
|
+
alias_method :logger_fin, :logger_message_fin
|
97
|
+
|
98
|
+
#=begin
|
99
|
+
def logger_fmt0(logrArgs)
|
100
|
+
logrArgs.is_a?(Hash) || raise(ArgumentError,"logrArgs >#{logrArgs}< not hash",caller)
|
101
|
+
logrArgs.inject([]) {|s, (k,v)| s << "#{k} >#{v.class}< >#{v}<"}
|
102
|
+
end
|
103
|
+
#=end
|
104
|
+
#=begin
|
105
|
+
def logger_fmt00(logrArgs)
|
106
|
+
logrArgs.is_a?(Hash) || raise(ArgumentError,"logrArgs >#{logrArgs}< not hash",caller)
|
107
|
+
logrArgs.inject([]) {|s, (k,v)| s << "#{k} >#{v.class}<"}
|
108
|
+
end
|
109
|
+
#=end
|
110
|
+
#=begin
|
111
|
+
def logger_fmt1(logrArgs)
|
112
|
+
logrArgs.is_a?(Hash) || raise(ArgumentError,"logrArgs >#{logrArgs}< not hash",caller)
|
113
|
+
logrArgs.inject([]) {|s, (k,v)| s << "#{k} >#{v.whoami?}< >#{v}<"}
|
114
|
+
end
|
115
|
+
#=end
|
116
|
+
#=begin
|
117
|
+
def logger_fmt2(logrArgs)
|
118
|
+
logrArgs.is_a?(Hash) || raise(ArgumentError,"logrArgs >#{logrArgs}< not hash",caller)
|
119
|
+
logrArgs.inject([]) {|s, (k,v)| s << "#{k} >#{v.whoami?}<"}
|
120
|
+
end
|
121
|
+
#=end
|
122
|
+
|
123
|
+
alias_method :logger_fmt_kls, :logger_fmt0
|
124
|
+
alias_method :logger_fmt_kls_only, :logger_fmt00
|
125
|
+
alias_method :logger_fmt_who, :logger_fmt1
|
126
|
+
alias_method :logger_fmt_who_only, :logger_fmt2
|
127
|
+
|
128
|
+
=begin
|
129
|
+
alias_method :potrubi_bootstrap_logger, :logger_message
|
130
|
+
alias_method :potrubi_bootstrap_logger_me, :logger_me
|
131
|
+
alias_method :potrubi_bootstrap_logger_mx, :logger_mx
|
132
|
+
alias_method :potrubi_bootstrap_logger_ms, :logger_ms
|
133
|
+
alias_method :potrubi_bootstrap_logger_ca, :logger_ca
|
134
|
+
alias_method :potrubi_bootstrap_logger_fmt_class, :logger_fmt0
|
135
|
+
alias_method :potrubi_bootstrap_logger_fmt_who, :logger_fmt0
|
136
|
+
alias_method :potrubi_bootstrap_logger_fmt_who_only, :logger_fmt00
|
137
|
+
=end
|
138
|
+
|
139
|
+
def logger_info(*a, &b)
|
140
|
+
logger_generic(:info, *a, &b)
|
141
|
+
end
|
142
|
+
def logger_debug(*a, &b)
|
143
|
+
logger_generic(:debug, *a, &b)
|
144
|
+
end
|
145
|
+
def logger_warn(*a, &b)
|
146
|
+
logger_generic(:warn, *a, &b)
|
147
|
+
end
|
148
|
+
def logger_error(*a, &b)
|
149
|
+
logger_generic(:error, *a, &b)
|
150
|
+
end
|
151
|
+
def logger_fatal(*a, &b)
|
152
|
+
logger_generic(:fatal, *a, &b)
|
153
|
+
end
|
154
|
+
def logger_unknown(*a, &b)
|
155
|
+
logger_generic(:unknown, *a, &b)
|
156
|
+
end
|
157
|
+
|
158
|
+
def logger_generic(logType, logEye, *logArgs, &logBlok)
|
159
|
+
$DEBUG && begin
|
160
|
+
logTypeCheck = [logType] - [:warn, :debug, :info, :error, :fatal, :unknown]
|
161
|
+
|
162
|
+
logTypeCheck.empty? || raise_exception(ArgumentError, "log type >#{logType}< unknown")
|
163
|
+
|
164
|
+
#logger.__send__(logType, *logArgs, &logBlok)
|
165
|
+
logger.__send__(logType, *logEye) { logger_fmt(*logArgs) }
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
__END__
|
176
|
+
|
177
|
+
IGR::Mixin::Logger.instance_methods.each {|m| puts("Lgr Inst Mth >#{m}<")}
|
178
|
+
|
@@ -0,0 +1,226 @@
|
|
1
|
+
|
2
|
+
# potrubi paths and names methods
|
3
|
+
|
4
|
+
require_relative '../bootstrap'
|
5
|
+
|
6
|
+
#requireList = %w(bootstrap)
|
7
|
+
#requireList.each {|r| require_relative "#{r}"}
|
8
|
+
|
9
|
+
mixinContent = Module.new do
|
10
|
+
|
11
|
+
# Fundamental Methods
|
12
|
+
# ###################
|
13
|
+
|
14
|
+
#=begin
|
15
|
+
def transform_pathandname_or_croak(transformSpec, *transformData)
|
16
|
+
eye = :tfm_pan
|
17
|
+
|
18
|
+
logrArgs = potrubi_bootstrap_logger_fmt_who(:spec => transformSpec, :data => transformData)
|
19
|
+
|
20
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, logrArgs)
|
21
|
+
|
22
|
+
transformDefs = case transformSpec
|
23
|
+
when Proc, Symbol, Array then [*transformSpec].compact
|
24
|
+
#when Array then transformSpec
|
25
|
+
###mustbe_hashs_or_croak(transformSpec)
|
26
|
+
else
|
27
|
+
potrubi_bootstrap_surprise_exception(transformSpec, eye, "transformSpec is what?")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
transformResult = transformDefs.inject(transformData) do |s, transformCode|
|
32
|
+
###transformCode = transformDef[:transform]
|
33
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye,"INJ BEG", potrubi_bootstrap_logger_fmt_who(:transformCode => transformCode, :s => s))
|
34
|
+
case transformCode
|
35
|
+
when Proc then transformCode.call(s)
|
36
|
+
when Symbol then __send__(transformCode, s)
|
37
|
+
when Array then
|
38
|
+
case
|
39
|
+
when transformCode.last.is_a?(Proc) then
|
40
|
+
transformArgs = transformCode[0, transformCode.size - 1]
|
41
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye,"PROC ON METHOD", potrubi_bootstrap_logger_fmt_who(:transformArgs => transformArgs))
|
42
|
+
s.__send__(*transformArgs, &(transformCode.last))
|
43
|
+
else
|
44
|
+
s.__send__(*transformCode)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
potrubi_bootstrap_surprise_exception(transformCode, eye, "transformCode is what?")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:result => transformResult), logrArgs)
|
52
|
+
|
53
|
+
transformResult
|
54
|
+
|
55
|
+
end
|
56
|
+
#=end
|
57
|
+
|
58
|
+
|
59
|
+
# Core Methods
|
60
|
+
# ############
|
61
|
+
|
62
|
+
#=begin
|
63
|
+
def normalise_pathandname_names_syntax_or_croak(*names, &block)
|
64
|
+
eye = :nrm_pan_ns_syn
|
65
|
+
|
66
|
+
nameNorm = names.flatten.compact.join('::').gsub('\\','::').gsub('/','::').gsub(':::', '::').sub(/(\.\w*)?\Z/,'')
|
67
|
+
|
68
|
+
potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(:name => nameNorm, :names => names))
|
69
|
+
|
70
|
+
nameNorm
|
71
|
+
|
72
|
+
end
|
73
|
+
#=end
|
74
|
+
|
75
|
+
#=begin
|
76
|
+
def normalise_pathandname_hier_drop_while(*names, &block)
|
77
|
+
r = names.flatten.compact.drop_while(&block)
|
78
|
+
potrubi_bootstrap_logger_ca(:nrm_pan_drop_while, potrubi_bootstrap_logger_fmt_who(:r => r, :names => names))
|
79
|
+
r
|
80
|
+
end
|
81
|
+
#=end
|
82
|
+
|
83
|
+
#=begin
|
84
|
+
def normalise_pathandname_hier_split_at(*names, &splitBlok)
|
85
|
+
a = names.flatten
|
86
|
+
i = a.find_index(&splitBlok)
|
87
|
+
|
88
|
+
r = case i
|
89
|
+
when NilClass then [a] # not found: all are "before"
|
90
|
+
when Fixnum then
|
91
|
+
[a[0, i], a[i+1, a.size - i - 1], a[i], i] # before, after, match value and index
|
92
|
+
else
|
93
|
+
potrubi_bootstrap_surprise_exception(i, eye, "a >#{a}< i is what?")
|
94
|
+
end
|
95
|
+
|
96
|
+
potrubi_bootstrap_logger_ca(:nrm_pan_h_split_at, potrubi_bootstrap_logger_fmt_who(:r => r, :names => names))
|
97
|
+
|
98
|
+
r
|
99
|
+
end
|
100
|
+
#=end
|
101
|
+
|
102
|
+
#=begin
|
103
|
+
def normalise_pathandname_hier_from_lib(*names) # from as in after
|
104
|
+
r = normalise_pathandname_hier_split_at(*names) {|v| v.downcase == 'lib' }
|
105
|
+
q = case
|
106
|
+
when r.size == 1 then r.first # no match; use all
|
107
|
+
else
|
108
|
+
r[1] # the after
|
109
|
+
end
|
110
|
+
potrubi_bootstrap_logger_ca(:nrm_pan_h_from_lib, potrubi_bootstrap_logger_fmt_who(:q => q, :r => r, :names => names))
|
111
|
+
q
|
112
|
+
end
|
113
|
+
#=end
|
114
|
+
|
115
|
+
#=begin
|
116
|
+
def normalise_pathandname_names_elements(*names)
|
117
|
+
versionSuffixRegexp = Regexp.new('(.+)_v\d+.*\Z')
|
118
|
+
r = names.flatten.compact.map {|n| m = n.to_s; (mD = m.to_s.match(versionSuffixRegexp)) ? mD[1] : m}.map {|n| p = n.split('_'); p.map {|q| q[0] = q.chr.upcase; q}.join }
|
119
|
+
potrubi_bootstrap_logger_ca(:nrm_pan_ns_eles, potrubi_bootstrap_logger_fmt_who(:r => r, :names => names))
|
120
|
+
r
|
121
|
+
end
|
122
|
+
#=end
|
123
|
+
|
124
|
+
#=begin
|
125
|
+
def normalise_pathandname_paths_or_croak(*paths, &block)
|
126
|
+
eye = :nrm_pan_ps
|
127
|
+
pathNorm = begin
|
128
|
+
pathNomn = paths.flatten.compact.join('/').gsub('\\', '/').gsub('::', '/').gsub('//', '/')
|
129
|
+
#pathFull = (pathNomn =~ /\A\./) ? ::File.expand_path(pathNomn) : pathNomn
|
130
|
+
File.expand_path(pathNomn)
|
131
|
+
end
|
132
|
+
|
133
|
+
potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(:pathNorm => pathNorm, :paths => paths))
|
134
|
+
pathNorm
|
135
|
+
end
|
136
|
+
alias_method :normalise_pathandname_path_or_croak, :normalise_pathandname_paths_or_croak
|
137
|
+
#=end
|
138
|
+
|
139
|
+
#=begin
|
140
|
+
def normalise_pathandname_names_to_hier_or_croak(*names, &block)
|
141
|
+
eye = :nrm_pan_ns_2_h
|
142
|
+
|
143
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(:names => names))
|
144
|
+
|
145
|
+
nameHier = transform_pathandname_or_croak([:normalise_pathandname_names_syntax_or_croak,
|
146
|
+
[:split, '::'],
|
147
|
+
:normalise_pathandname_hier_from_lib,
|
148
|
+
:normalise_pathandname_names_elements,
|
149
|
+
Kernel.block_given? ? [:map, block] : nil,
|
150
|
+
], *names)
|
151
|
+
|
152
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:hier => nameHier, :names => names))
|
153
|
+
|
154
|
+
potrubi_bootstrap_mustbe_array_or_croak(nameHier, eye)
|
155
|
+
|
156
|
+
end
|
157
|
+
alias_method :normalise_pathandname_name_to_hier_or_croak, :normalise_pathandname_names_to_hier_or_croak
|
158
|
+
#=end
|
159
|
+
|
160
|
+
#=begin
|
161
|
+
def normalise_pathandname_paths_to_hier_or_croak(*paths, &block)
|
162
|
+
eye = :nrm_pan_ps_2_h
|
163
|
+
|
164
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, "paths >#{paths}<")
|
165
|
+
|
166
|
+
pathHier = transform_pathandname_or_croak([:normalise_pathandname_paths_or_croak,
|
167
|
+
[:split, '/'],
|
168
|
+
Kernel.block_given? ? [:map, block] : nil,
|
169
|
+
], *paths)
|
170
|
+
|
171
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, "pathhier >#{pathHier.whoami?}< >#{pathHier}< paths >#{paths}<")
|
172
|
+
|
173
|
+
potrubi_bootstrap_mustbe_array_or_croak(pathHier, eye)
|
174
|
+
|
175
|
+
end
|
176
|
+
alias_method :normalise_pathandname_path_to_hier_or_croak, :normalise_pathandname_paths_to_hier_or_croak
|
177
|
+
#=end
|
178
|
+
|
179
|
+
# Derivative Methods
|
180
|
+
# ##################
|
181
|
+
|
182
|
+
#=begin
|
183
|
+
def normalise_pathandname_names_or_croak(*names, &block)
|
184
|
+
eye = :nrm_pan_ns
|
185
|
+
nameNorm = normalise_pathandname_names_to_hier_or_croak(*names, &block).join('::')
|
186
|
+
potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(:name => nameNorm, :names => names))
|
187
|
+
nameNorm
|
188
|
+
end
|
189
|
+
alias_method :normalise_pathandname_name_or_croak, :normalise_pathandname_names_or_croak
|
190
|
+
#=end
|
191
|
+
|
192
|
+
#=begin
|
193
|
+
def find_pathandname_names_hier_from_lib_or_croak(*names, &block)
|
194
|
+
eye = :f_pan_ns_hier_fr_lib
|
195
|
+
|
196
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(:names => names))
|
197
|
+
|
198
|
+
nameHier = normalise_pathandname_names_to_hier_or_croak(*names)
|
199
|
+
|
200
|
+
libHierNom = nameHier.reverse.drop_while {|v| (v.downcase != 'Lib') }.reverse
|
201
|
+
|
202
|
+
libHierNom.shift # the lib
|
203
|
+
|
204
|
+
libHierMap = Kernel.block_given? ? libHierNom.map {|m| block.call(m)} : libHierNom
|
205
|
+
|
206
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:libHierMap => libHierMap, :libHierNom => libHierNom, :name_hier => nameHier, :names => names))
|
207
|
+
|
208
|
+
potrubi_bootstrap_mustbe_array_or_croak(libHier)
|
209
|
+
|
210
|
+
end
|
211
|
+
#=end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
module Potrubi
|
216
|
+
module Mixin
|
217
|
+
module PathAndNames
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
Potrubi::Mixin::PathAndNames.__send__(:include, mixinContent) # Instance Methods
|
223
|
+
|
224
|
+
|
225
|
+
__END__
|
226
|
+
|
@@ -0,0 +1,192 @@
|
|
1
|
+
|
2
|
+
# potrubi mixin persistence
|
3
|
+
|
4
|
+
# various file, etc methods
|
5
|
+
|
6
|
+
require_relative '../core'
|
7
|
+
|
8
|
+
requireList = %w(util filesys)
|
9
|
+
requireList.each {|r| require_relative "#{r}"}
|
10
|
+
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
mixinContent = Module.new do
|
14
|
+
|
15
|
+
include Potrubi::Mixin::Filesys
|
16
|
+
|
17
|
+
def write_yaml_file_or_croak(yamlPath, yamlData)
|
18
|
+
eye = :w_yaml
|
19
|
+
File.directory?(yamlPath) || create_path_directory_or_croak(yamlPath)
|
20
|
+
File.open(yamlPath, 'w') {|yamlHndl| YAML.dump(yamlData, yamlHndl) }
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_yaml_file_or_croak(yamlPath, &yamlBlok)
|
25
|
+
eye = :r_yaml
|
26
|
+
|
27
|
+
yamlData = case
|
28
|
+
when (p = is_value_yaml_path?(yamlPath)) then YAML.load(File.read(p))
|
29
|
+
else
|
30
|
+
missing_exception(yamlPath, eye, 'yamlPath not found / not a file')
|
31
|
+
end
|
32
|
+
|
33
|
+
r = Kernel.block_given? ? yamlBlok.call(yamlData) : yamlData
|
34
|
+
|
35
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(:yamlPath => yamlPath), logger_fmt_kls_only(:yamlData => r))
|
36
|
+
|
37
|
+
r
|
38
|
+
end
|
39
|
+
|
40
|
+
# 'reading' a ruby configuration sources mean instance_eval-ing the
|
41
|
+
# code and returning the final value
|
42
|
+
|
43
|
+
def read_ruby_configuration_source_or_croak(rubyPath, &rubyBlok)
|
44
|
+
eye = :r_ruby
|
45
|
+
|
46
|
+
rubyText = case
|
47
|
+
when (p = is_value_ruby_configuration_source?(rubyPath)) then File.open(p).readlines.join("\n")
|
48
|
+
else
|
49
|
+
missing_exception(rubyPath, eye, 'rubyPath not found / not a file')
|
50
|
+
end
|
51
|
+
|
52
|
+
###puts("RUBY TETX >#{rubyText.class}< >#{rubyText}<")
|
53
|
+
|
54
|
+
rubyData = instance_eval(rubyText)
|
55
|
+
|
56
|
+
r = Kernel.block_given? ? rubyBlok.call(rubyData) : rubyData
|
57
|
+
|
58
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(:rubyPath => rubyPath), logger_fmt_kls(:rubyData => r))
|
59
|
+
|
60
|
+
r
|
61
|
+
end
|
62
|
+
|
63
|
+
# generalises configuration sources
|
64
|
+
|
65
|
+
# Read configuration sources
|
66
|
+
# Take hard line and raise exception if not a source
|
67
|
+
# Unless blok is given and retruns reuslt of block
|
68
|
+
|
69
|
+
def read_configuration_sources_or_croak(srceArgs, &srceBlok)
|
70
|
+
eye = :r_cfg_srces
|
71
|
+
|
72
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(srceArgs: srceArgs), logger_fmt_kls(srceBlok: srceBlok))
|
73
|
+
|
74
|
+
srceData = potrubi_util_map_hash_v(srceArgs) do | srceName, srceValue |
|
75
|
+
##is_value_configuration_source?(srceValue) ? read_configuration_source_or_croak(srceValue) : (Kernel.block_given? ? srceBlok.call(srceName, srceValue) : potrubi_bootstrap_surprise_exception(srceValue, eye, "srceName >#{srceName}< srceValue not a configuration source"))
|
76
|
+
read_configuration_source_or_croak(srceValue, &srceBlok)
|
77
|
+
end
|
78
|
+
|
79
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(srceData: srceData))
|
80
|
+
|
81
|
+
mustbe_hash_or_croak(srceData, eye, "srceData not hash")
|
82
|
+
|
83
|
+
end
|
84
|
+
alias_method :read_configuration_files_or_croak, :read_configuration_sources_or_croak
|
85
|
+
|
86
|
+
# Tolerate non-sources
|
87
|
+
|
88
|
+
def read_maybe_configuration_sources_or_croak(srceArgs)
|
89
|
+
read_configuration_sources_or_croak(srceArgs) {|v| v}
|
90
|
+
end
|
91
|
+
|
92
|
+
# Read the actual source
|
93
|
+
|
94
|
+
def read_configuration_source_or_croak(srceSpec, &srceBlok)
|
95
|
+
eye = :'r_cfg_src'
|
96
|
+
|
97
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(srceSpec: srceSpec), logger_fmt_kls(srceBlok: srceBlok))
|
98
|
+
|
99
|
+
srceType = is_value_configuration_source?(srceSpec)
|
100
|
+
|
101
|
+
srceData = case srceType
|
102
|
+
when Symbol
|
103
|
+
case srceType
|
104
|
+
when :HASH then srceSpec # nothing to do
|
105
|
+
when :YAML then read_yaml_file_or_croak(srceSpec)
|
106
|
+
when :RUBY then read_ruby_configuration_source_or_croak(srceSpec)
|
107
|
+
else
|
108
|
+
surprise_exception(srceType, eye, "srceType not a known symbol")
|
109
|
+
end
|
110
|
+
else
|
111
|
+
Kernel.block_given? ? srceBlok.call(srceSpec) : potrubi_bootstrap_surprise_exception(srceSpec, eye, "srceSpec not a configuration source")
|
112
|
+
end
|
113
|
+
|
114
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls_only(srceType: srceType), logger_fmt_kls(srceBlok: srceBlok), logger_fmt_kls_only(srceData: srceData))
|
115
|
+
|
116
|
+
srceData
|
117
|
+
end
|
118
|
+
|
119
|
+
def read_maybe_configuration_sources_list_or_croak(*srceArgs)
|
120
|
+
read_configuration_sources_list_or_croak(*srceArgs) {|v| v}
|
121
|
+
end
|
122
|
+
|
123
|
+
def read_configuration_sources_list_or_croak(*srceArgs, &srceBlok)
|
124
|
+
eye = 'r_cfg_srcs_lst'
|
125
|
+
|
126
|
+
# srceBlok is used on hash merges for duplicate keys
|
127
|
+
|
128
|
+
$DEBUG && logger_me(eye, logger_fmt_kls(srceArgs: srceArgs, srceBlok: srceBlok))
|
129
|
+
|
130
|
+
srceData = srceArgs.map { | srceArg | read_configuration_source_or_croak(srceArg, &srceBlok)}
|
131
|
+
|
132
|
+
$DEBUG && logger_mx(eye, logger_fmt_kls(srceData: srceData, srceBlok: srceBlok))
|
133
|
+
|
134
|
+
mustbe_array_or_croak(srceData, eye, "srceData not array")
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
def is_value_configuration_source?(srceArgs)
|
139
|
+
eye = :'is_val_cfg_src?'
|
140
|
+
srceType = case
|
141
|
+
when srceArgs.is_a?(Hash) then :HASH
|
142
|
+
when (r = is_value_yaml_path?(srceArgs)) then :YAML
|
143
|
+
when (r = is_value_ruby_configuration_source?(srceArgs)) then :RUBY
|
144
|
+
else
|
145
|
+
nil
|
146
|
+
end
|
147
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(srceType: srceType), logger_fmt_kls(srceArgs: srceArgs), )
|
148
|
+
srceType
|
149
|
+
end
|
150
|
+
|
151
|
+
# specific source type tests (TODO: xml?)
|
152
|
+
|
153
|
+
def is_value_yaml_path?(yamlPathNom, &yamlBlok)
|
154
|
+
eye = :is_yaml_path?
|
155
|
+
|
156
|
+
yamlPathNrm = case
|
157
|
+
#when is_value_file?(yamlPathNom) then yamlPathNom
|
158
|
+
when is_value_file?(yamlPathNom) && ((File.extname(yamlPathNom) == '.yaml') || (File.extname(yamlPathNom) == '.yml')) then yamlPathNom
|
159
|
+
when is_value_file?(r = "#{yamlPathNom}.yml") then r
|
160
|
+
when is_value_file?(r = "#{yamlPathNom}.yaml") then r
|
161
|
+
else
|
162
|
+
nil
|
163
|
+
end
|
164
|
+
|
165
|
+
r = Kernel.block_given? ? yamlBlok.call(yamlPathNrm) : yamlPathNrm
|
166
|
+
|
167
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(yamlPath: yamlPathNrm, yamlPathNom: r))
|
168
|
+
|
169
|
+
r
|
170
|
+
end
|
171
|
+
|
172
|
+
def is_value_ruby_configuration_source?(rubyPathNom, &rubyBlok)
|
173
|
+
eye = :is_ruby_path?
|
174
|
+
|
175
|
+
rubyPathNrm = case
|
176
|
+
when (is_value_file?(rubyPathNom) && (File.extname(rubyPathNom) == '.rb')) then rubyPathNom
|
177
|
+
else
|
178
|
+
nil
|
179
|
+
end
|
180
|
+
|
181
|
+
r = Kernel.block_given? ? rubyBlok.call(rubyPathNrm) : rubyPathNrm
|
182
|
+
|
183
|
+
$DEBUG && logger_ca(eye, logger_fmt_kls(rubyPath: rubyPathNrm, rubyPathNom: r))
|
184
|
+
|
185
|
+
r
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
mixinConstant = Potrubi::Core.assign_mixin_constant_or_croak(mixinContent, :Potrubi, :Mixin, :Persistence)
|
190
|
+
|
191
|
+
__END__
|
192
|
+
|