potrubi 0.0.3 → 0.0.4
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/lib/potrubi.rb +1 -1
- data/lib/potrubi/bootstrap.rb +1 -1
- data/lib/potrubi/core.rb +3 -3
- data/lib/potrubi/dsl.rb +86 -0
- data/lib/potrubi/dsl/accessor.rb +76 -0
- data/lib/potrubi/dsl/cache_2d.rb +811 -0
- data/lib/potrubi/dsl/contract.rb +731 -0
- data/lib/potrubi/dsl/super.rb +517 -0
- data/lib/potrubi/klass/syntax/alias.rb +150 -0
- data/lib/potrubi/klass/syntax/braket.rb +115 -25
- data/lib/potrubi/klass/syntax/builder.rb +45 -0
- data/lib/potrubi/klass/syntax/method.rb +436 -0
- data/lib/potrubi/klass/syntax/mixin/name_generation.rb +85 -0
- data/lib/potrubi/klass/syntax/mixin/new_aliases.rb +76 -0
- data/lib/potrubi/klass/syntax/mixin/new_brakets.rb +89 -0
- data/lib/potrubi/klass/syntax/mixin/new_methods.rb +158 -0
- data/lib/potrubi/klass/syntax/mixin/new_snippets.rb +74 -0
- data/lib/potrubi/klass/syntax/mixin/new_statements.rb +0 -0
- data/lib/potrubi/klass/syntax/mixin/statement_management.rb +69 -0
- data/lib/potrubi/klass/syntax/mixin/synel_management.rb +168 -0
- data/lib/potrubi/klass/syntax/snippet.rb +386 -0
- data/lib/potrubi/klass/syntax/statement.rb +91 -0
- data/lib/potrubi/klass/syntax/super.rb +88 -0
- data/lib/potrubi/mixin/bootstrap_common.rb +38 -12
- data/lib/potrubi/mixin/configuration.rb +31 -3
- data/lib/potrubi/mixin/contract.rb +5 -14
- data/lib/potrubi/mixin/contract/recipes.rb +307 -0
- data/lib/potrubi/mixin/dynamic-recipes.rb +1 -11
- data/lib/potrubi/mixin/dynamic.rb +223 -115
- data/lib/potrubi/mixin/exception.rb +3 -22
- data/lib/potrubi/mixin/filesys.rb +5 -21
- data/lib/potrubi/mixin/initialize.rb +11 -6
- data/lib/potrubi/mixin/konstant.rb +14 -118
- data/lib/potrubi/mixin/logger.rb +28 -41
- data/lib/potrubi/mixin/pathandnames.rb +4 -34
- data/lib/potrubi/mixin/persistence.rb +115 -10
- data/lib/potrubi/mixin/script.rb +0 -5
- data/lib/potrubi/mixin/{text-snippets → snippet-dictionaries}/methods-text-snippets.rb +138 -49
- data/lib/potrubi/mixin/{text-snippets.rb → snippet-manager.rb} +51 -39
- data/lib/potrubi/mixin/util.rb +66 -20
- data/lib/potrubi/version.rb +1 -1
- data/test/potrubi/mixin/bootstrap_common.rb +205 -0
- data/test/potrubi/mixin/konstant.rb +216 -0
- data/test/potrubi/mixin/logger.rb +124 -0
- data/test/ts_bootstrap_mixins.rb +16 -0
- data/test/ts_core_mixins.rb +7 -0
- metadata +31 -6
- data/lib/potrubi/mixin/contract-recipes.rb +0 -226
@@ -11,7 +11,6 @@ metaclassMethods = Module.new do
|
|
11
11
|
include Potrubi::Bootstrap
|
12
12
|
include Potrubi::Mixin::Dynamic
|
13
13
|
|
14
|
-
#=begin
|
15
14
|
def recipe_new(tgtMod, newSpecs, &block)
|
16
15
|
dynamic_define_methods(tgtMod, newSpecs) do | newName, newKlass |
|
17
16
|
|
@@ -33,20 +32,15 @@ metaclassMethods = Module.new do
|
|
33
32
|
|
34
33
|
end
|
35
34
|
end
|
36
|
-
|
37
|
-
#=begin
|
35
|
+
|
38
36
|
def recipe_rescue_croak(tgtMod, croakSpecs, &block)
|
39
37
|
dynamic_define_methods(tgtMod, croakSpecs) { | rescueName, rescueValue | "def #{rescueName}(*a, &b); #{rescueName}_or_croak(*a, &b) rescue #{rescueValue || 'nil'}; end\n" }
|
40
38
|
end
|
41
|
-
#=end
|
42
39
|
|
43
|
-
#=begin
|
44
40
|
def recipe_aliases(tgtMod, aliasSpecs, &block)
|
45
41
|
dynamic_define_methods(tgtMod, aliasSpecs) { | aliasName, realName | "alias_method :'#{aliasName}', :'#{realName}';\n" }
|
46
42
|
end
|
47
|
-
#=end
|
48
43
|
|
49
|
-
#=begin
|
50
44
|
def recipe_croak_rescue(targetModule, croakArgs={}, &croakBlok)
|
51
45
|
eye = :rcp_crk_rsc
|
52
46
|
|
@@ -78,12 +72,8 @@ metaclassMethods = Module.new do
|
|
78
72
|
|
79
73
|
self
|
80
74
|
end
|
81
|
-
#=end
|
82
|
-
|
83
|
-
|
84
75
|
|
85
76
|
end
|
86
|
-
#=end
|
87
77
|
|
88
78
|
module Potrubi
|
89
79
|
module Mixin
|
@@ -12,21 +12,19 @@ metaclassMethods = Module.new do
|
|
12
12
|
#=begin
|
13
13
|
def dynamic_apply_edits(editSpecInput, *textValues, &block)
|
14
14
|
eye = :dyn_apy_edts
|
15
|
-
|
16
|
-
|
17
|
-
#editSpec.is_a?(Hash) || editSpec.is_a?(Enumerator) || (raise ArgumentError,"editSpec >#{editSpec.class}< >#{editSpec}< not hash")
|
15
|
+
eyeTale = '"TEXT EDITS'
|
16
|
+
|
18
17
|
editSpec = case editSpecInput
|
19
18
|
when Hash then editSpecInput
|
20
19
|
when Array then dynamic_merge_edits(editSpecInput)
|
21
20
|
when NilClass then nil
|
22
21
|
else
|
23
22
|
potrubi_bootstrap_surpise_exception(editSpecInput, eye, "editSpecInput not has, array or nil")
|
24
|
-
###nil # will error
|
25
23
|
end
|
26
24
|
|
27
25
|
editSpec && potrubi_bootstrap_mustbe_hash_or_croak(editSpec, "editSpec not hash")
|
28
26
|
|
29
|
-
|
27
|
+
potrubi_bootstrap_logger_me(eye, eyeTale, "editSpec", editSpec, "textValues >\n#{textValues}")
|
30
28
|
|
31
29
|
textValue = textValues.flatten.compact.join("\n")
|
32
30
|
|
@@ -43,35 +41,26 @@ metaclassMethods = Module.new do
|
|
43
41
|
((recurseCnt +=1) <= recurseMax) || potrubi_bootstrap_surprise_exception(recurseCnt, eye, "recurseMax >#{recurseMax}< exceeded")
|
44
42
|
|
45
43
|
textValue = newtextValue || textValue
|
46
|
-
|
47
|
-
|
44
|
+
|
45
|
+
newtextValue = editSpec.inject(textValue) { |txt, (key, val)| txt.gsub(/#{key.to_s}/,"#{val}") }
|
46
|
+
|
48
47
|
end
|
49
48
|
|
50
49
|
newtextValue
|
51
50
|
|
52
51
|
end
|
53
52
|
|
54
|
-
# support for uniquenesses needed?
|
55
|
-
|
56
|
-
#while (textFinal =~ /METHOD_UNIQUENESS/)
|
57
|
-
# textFinal = textFinal.sub(/METHOD_UNIQUENESS/, rand(1000000000000).to_s) # Each UNQIUENESS is unique!
|
58
|
-
#end
|
59
|
-
|
60
53
|
#potrubi_bootstrap_logger_mx(eye, eyeTale, "textFinal >#{textFinal.class}< >\n#{textFinal}\n<")
|
61
54
|
|
62
55
|
textFinal
|
63
56
|
|
64
57
|
end
|
65
|
-
#=end
|
66
58
|
|
67
|
-
|
68
|
-
|
69
|
-
r = edits.flatten.compact.inject({}) {|s, h| s.merge(potrubi_bootstrap_mustbe_hash_or_croak(h))}
|
59
|
+
def dynamic_merge_edits(*edits, &editBlok)
|
60
|
+
r = edits.flatten.compact.inject({}) {|s, h| s.merge(potrubi_bootstrap_mustbe_hash_or_croak(h), &editBlok)}
|
70
61
|
r.empty? ? nil : r
|
71
62
|
end
|
72
|
-
#=end
|
73
63
|
|
74
|
-
#=begin
|
75
64
|
def dynamic_define_methods(targetModule, methodDefs, dynArgs=nil, &dynBlok)
|
76
65
|
eye = :dyn_def_mtds
|
77
66
|
|
@@ -85,8 +74,6 @@ metaclassMethods = Module.new do
|
|
85
74
|
|
86
75
|
editArgs = dynArgs && dynArgs[:edit]
|
87
76
|
|
88
|
-
#methodTexts = nil # will hold texts for methods, if any (could be all define_methods)
|
89
|
-
|
90
77
|
dynSpecsAll = methodDefs.map do | mtdKey, mtdVal |
|
91
78
|
|
92
79
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, "BEG MTH mtdKey >#{mtdKey.class}< >#{mtdKey}< mtdVal >#{mtdVal.class}< >#{mtdVal.class}< editArgs >#{editArgs .class}< >#{editArgs}<")
|
@@ -104,33 +91,8 @@ metaclassMethods = Module.new do
|
|
104
91
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, "CASE GEN mtdKey >#{mtdKey.class}< >#{mtdKey}< mtdVal >#{mtdVal.class}< >#{mtdVal}< dynResultsBlok >#{dynResultsBlok.class}< >#{dynResultsBlok}<")
|
105
92
|
|
106
93
|
editMtd = nil # no default edits
|
107
|
-
|
108
|
-
|
109
|
-
case dynResult
|
110
|
-
when NilClass then nil
|
111
|
-
when Array then
|
112
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE ARRAY mtdKey >#{mtdKey.class}< >#{mtdKey}< dynResult >#{dynResult.class}< >#{dynResult}<")
|
113
|
-
dynResult # expected to have got is all right
|
114
|
-
when String, Symbol then
|
115
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE STRING, SYMBOL mtdKey >#{mtdKey.class}< >#{mtdKey}< dynResult >#{dynResult.class}< >#{dynResult}<")
|
116
|
-
#{:edit => [editMtd, editArgs], :spec => dynResult}
|
117
|
-
{spec: dynResult}
|
118
|
-
when Proc then
|
119
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE PROC mtdKey >#{mtdKey.class}< >#{mtdKey}< dynResult >#{dynResult.class}< >#{dynResult}<")
|
120
|
-
{name: mtdKey, spec: dynResult}
|
121
|
-
when Hash then
|
122
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE HASH mtdVal >#{mtdKey.class}< >#{mtdKey}< dynResult >#{dynResult.class}< >#{dynResult}<")
|
123
|
-
dynResult # expected to have gotten it right
|
124
|
-
else
|
125
|
-
potrubi_bootstrap_surprise_exception(dynResult, eye, "dynResult is what?")
|
126
|
-
end
|
127
|
-
|
128
|
-
end.flatten.compact
|
129
|
-
|
130
|
-
|
131
|
-
dynSpecs = [*dynResultsNorm].map do | dynResult |
|
132
|
-
|
133
|
-
potrubi_bootstrap_mustbe_hash_or_croak(dynResult, eye, "dynResult not hash")
|
94
|
+
|
95
|
+
dynSpecs = dynamic_define_methods_normalise_specifications(mtdKey, *dynResultsBlok) do | dynResult |
|
134
96
|
|
135
97
|
editAll = case
|
136
98
|
when dynResult.has_key?(:edit) then # edit key set?
|
@@ -148,55 +110,197 @@ metaclassMethods = Module.new do
|
|
148
110
|
|
149
111
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "FIN MTH mtdKey >#{mtdKey.class}< >#{mtdKey}< dynSpecs >#{dynSpecs.class}< >#{dynSpecs}<")
|
150
112
|
|
151
|
-
|
152
|
-
#dynamic_define_methods_apply(targetModule, dynSpecs)
|
153
113
|
dynSpecs
|
114
|
+
|
154
115
|
end
|
155
116
|
|
156
117
|
dynamic_define_methods_apply(targetModule, dynSpecsAll)
|
157
118
|
|
158
|
-
|
159
119
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, "targetModule >#{targetModule.class}< >#{targetModule}< specs >#{methodDefs.class}< >#{methodDefs.class}< dynArgs >#{dynArgs.class}< >#{dynArgs}<")
|
120
|
+
|
160
121
|
self
|
161
122
|
|
162
123
|
end
|
163
|
-
#=end
|
164
124
|
|
165
|
-
|
166
|
-
|
125
|
+
def dynamic_define_methods_normalise_specifications(specName, *specsNom, &specBlok)
|
126
|
+
eye = :ddm_nrm_specs
|
127
|
+
eyeTale = 'DDM NRM SPEC'
|
128
|
+
|
129
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "specName >#{specName}< specsNom >#{specsNom.class}< >#{specsNom.size}< >#{specsNom}< specBlok >#{specBlok}<")
|
130
|
+
|
131
|
+
specsMap = specsNom.flatten(1).map.with_index do | specNom, specNdx |
|
132
|
+
|
133
|
+
case specNom
|
134
|
+
when NilClass then nil # convenient to allow nil
|
135
|
+
when Array then
|
136
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE ARRAY specName >#{specName.class}< >#{specName}< specNom >#{specNom.class}< >#{specNom}<")
|
137
|
+
specNom # expected to have got is all right
|
138
|
+
when String, Symbol then
|
139
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE STRING, SYMBOL specName >#{specName.class}< >#{specName}< specNom >#{specNom.class}< >#{specNom}<")
|
140
|
+
#{:edit => [editMtd, editArgs], :spec => specNom}
|
141
|
+
{spec: specNom}
|
142
|
+
when Proc then
|
143
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE PROC specName >#{specName.class}< >#{specName}< specNom >#{specNom.class}< >#{specNom}<")
|
144
|
+
{name: specName, spec: specNom}
|
145
|
+
#STOPHERECASEPROC
|
146
|
+
when Hash then
|
147
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "CASE HASH specName >#{specName.class}< >#{specName}< specNom >#{specNom.class}< >#{specNom}<")
|
148
|
+
specNom # expected to have gotten it right
|
149
|
+
else
|
150
|
+
potrubi_bootstrap_surprise_exception(specNom, eye, "specName >#{specName.class}< >#{specName}< specNom is what?")
|
151
|
+
end
|
152
|
+
|
153
|
+
end.flatten.compact
|
154
|
+
|
155
|
+
dynamic_define_methods_validate_specifications(*specsMap)
|
156
|
+
|
157
|
+
specsNrm = Kernel.block_given? ? specsMap.map {|s| specBlok.call(s)} : specsMap
|
158
|
+
|
159
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "specName >#{specName}< specsNrm >#{specsNrm.class}< >#{specsNrm.size}< >#{specsNrm.class}< specBlok >#{specBlok}<")
|
160
|
+
potrubi_bootstrap_mustbe_array_or_croak(specsNrm, eye)
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
# reduction in this context is consolidating edist
|
165
|
+
# alos resolving snippets
|
166
|
+
|
167
|
+
def dynamic_define_methods_reduce_specifications(targetModule, *specsNom, &specBlok)
|
168
|
+
eye = :ddm_rdc_specs
|
169
|
+
eyeTale = 'DDM RDC SPEC'
|
170
|
+
|
171
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "specsNom >#{specsNom.class}< >#{specsNom.size}< >#{specsNom.class}< specBlok >#{specBlok}<")
|
172
|
+
|
173
|
+
specsVal = dynamic_define_methods_validate_specifications(*specsNom)
|
174
|
+
|
175
|
+
specsNrm = specsVal.map do | specNom |
|
176
|
+
|
177
|
+
specEdit = specNom[:edit]
|
178
|
+
specSpec = specNom[:spec]
|
179
|
+
|
180
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "EDIT & SPEC specEdit >#{specEdit}< specSpec >#{specSpec.class}< >#{specSpec}<")
|
181
|
+
|
182
|
+
# Resolve any snippets
|
183
|
+
specSnippets = Potrubi::Mixin::SnippetManager.map_snippets_or_croak(:dynamic_methods, *specSpec)
|
184
|
+
|
185
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "SNIP", potrubi_bootstrap_logger_fmt_kls_size(specSnippets: specSnippets))
|
186
|
+
|
187
|
+
snipEdits = dynamic_merge_edits(specEdit) # cummlative edits
|
188
|
+
|
189
|
+
snipItems = specSnippets.map do | snipItem |
|
190
|
+
|
191
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "SNIP BEG", potrubi_bootstrap_logger_fmt_kls(snipItem: snipItem))
|
192
|
+
|
193
|
+
snipList = case snipItem
|
194
|
+
when Hash
|
195
|
+
|
196
|
+
if snipItem.has_key?(:edit) then
|
197
|
+
# collect any edits e.g. defaults. specEdit takes prescedence of snipEdits
|
198
|
+
snipEdits = dynamic_merge_edits(snipEdits, snipItem[:edit], specEdit)
|
199
|
+
end
|
200
|
+
|
201
|
+
case
|
202
|
+
when snipItem.has_key?(:proc) then
|
203
|
+
r = dynamic_define_methods_apply_procs(nil, snipItem.merge({edit: snipEdits, target: targetModule}))
|
204
|
+
dynamic_define_methods_reduce_specifications(targetModule, *r) # recurse
|
205
|
+
else
|
206
|
+
snipItem.merge({edit: snipEdits}) # roll up all edits
|
207
|
+
end
|
208
|
+
|
209
|
+
when String then {edit: snipEdits, spec: snipItem}
|
210
|
+
when Proc then specNom.merge({spec: snipItem})
|
211
|
+
else
|
212
|
+
potrubi_bootstrap_surprise_exception(snipItem, eye, "snipItem unexpected")
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "SNIP FIN", potrubi_bootstrap_logger_fmt_kls(snipList: snipList))
|
217
|
+
|
218
|
+
snipList
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end.flatten
|
223
|
+
|
224
|
+
dynamic_define_methods_validate_specifications(*specsNrm)
|
225
|
+
|
226
|
+
specsRdc = Kernel.block_given? ? specsNrm.map {|s| specBlok.call(s)} : specsNrm
|
227
|
+
|
228
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "specsRdc >#{specsRdc.class}< >#{specsRdc.size}< >#{specsRdc.class}< specBlok >#{specBlok}<")
|
229
|
+
|
230
|
+
potrubi_bootstrap_mustbe_array_or_croak(specsRdc, eye)
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
def dynamic_define_methods_validate_specifications(*specsNom, &specBlok)
|
235
|
+
eye = :ddm_val_specs
|
236
|
+
eyeTale = 'DDM VAL SPEC'
|
237
|
+
|
238
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "specsNom >#{specsNom.class}< >#{specsNom.size}< >#{specsNom.class}< specBlok >#{specBlok}<")
|
239
|
+
|
240
|
+
specKeys = [:edit, :spec, :name, :proc, :target]
|
241
|
+
|
242
|
+
specsNrm = specsNom.flatten.map.with_index do | specNom, specNdx |
|
243
|
+
|
244
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, "specNdx >#{specNdx}< spceSize >#{specNom.size}<", potrubi_bootstrap_logger_fmt_kls(specNom: specNom))
|
245
|
+
|
246
|
+
potrubi_bootstrap_mustbe_hash_or_croak(specNom, eye)
|
247
|
+
|
248
|
+
potrubi_bootstrap_mustbe_empty_or_croak(specNom.keys - specKeys, eye)
|
249
|
+
|
250
|
+
specNom
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
specsVal = Kernel.block_given? ? specsNrm.map {|s| specBlok.call(s)} : specsNrm
|
255
|
+
|
256
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "specsNom >#{specsVal.class}< >#{specsVal.size}< >#{specsVal.class}< specBlok >#{specBlok}<")
|
257
|
+
|
258
|
+
potrubi_bootstrap_mustbe_array_or_croak(specsVal, eye)
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
# expects an array of normalised and validated hashes
|
263
|
+
|
264
|
+
def dynamic_define_methods_apply(targetModule, *methodSpecsNom, &dynBlok)
|
167
265
|
eye = :ddm_apl
|
168
266
|
eyeTale = 'DDM APL'
|
169
267
|
|
170
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}< specs >#{
|
268
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}< specs >#{methodSpecsNom.class}< >#{methodSpecsNom.size}< >#{methodSpecsNom.class}< dynBlok >#{dynBlok}<")
|
171
269
|
|
270
|
+
# validate specs
|
271
|
+
methodSpecsRdc = dynamic_define_methods_reduce_specifications(targetModule, *methodSpecsNom)
|
272
|
+
|
273
|
+
# any methods specs with logic to apply?
|
274
|
+
methodSpecs = methodSpecsRdc
|
275
|
+
|
172
276
|
# try to merge all the text methods together
|
173
277
|
|
174
278
|
textMethods = []
|
175
279
|
|
176
|
-
methodSpecs.
|
280
|
+
methodSpecs.each_with_index do | methodSpec, methodNdx |
|
177
281
|
|
178
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, "methodNdx >#{methodNdx}< methodSpec >#{methodSpec.class}< >#{methodSpec}<")
|
282
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, "methodNdx >#{methodNdx}< methodSpec >#{methodSpec.class}< >#{methodSpec.class}<")
|
179
283
|
|
180
284
|
potrubi_bootstrap_mustbe_hash_or_croak(methodSpec)
|
181
285
|
|
182
286
|
case (specType = methodSpec[:spec])
|
183
287
|
when Proc then
|
184
288
|
|
185
|
-
specName = potrubi_bootstrap_mustbe_string_or_croak((r = methodSpec[:name]) ? r.to_s : nil)
|
289
|
+
specName = potrubi_bootstrap_mustbe_string_or_croak((r = methodSpec[:name]) ? r.to_s : nil, eye, "proc name is nil")
|
186
290
|
specProc = specType # potrubi_bootstrap_mustbe_proc_or_croak(mustbe_key_or_croak(methodSpec, :proc))
|
187
291
|
|
188
292
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "PROC BEG specName >#{specName.class}< >#{specName}< specProc >#{specProc.class}< >#{specProc}<")
|
189
293
|
|
190
|
-
textMethods.empty?
|
191
|
-
|
192
|
-
|
193
|
-
|
294
|
+
if (! textMethods.empty?) then # any text methods "waiting"; must be defined before proc
|
295
|
+
dynamic_define_methods_apply_texts(targetModule, *textMethods)
|
296
|
+
textMethods.clear # none wating now
|
297
|
+
end
|
194
298
|
|
195
299
|
targetModule.__send__(:define_method, specName.to_sym, &specProc)
|
196
300
|
|
197
301
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "PROC FIN specName >#{specName.class}< >#{specName}< specProc >#{specProc.class}< >#{specProc}<")
|
198
|
-
|
199
|
-
when String
|
302
|
+
|
303
|
+
when String then textMethods << methodSpec
|
200
304
|
when Array then textMethods << methodSpec
|
201
305
|
else
|
202
306
|
potrubi_bootstrap_surprise_exception(specType, "methodSpec >#{methodSpec.class}< >#{methodSpec.class}< specType >#{specType.class}< is what?")
|
@@ -204,7 +308,7 @@ metaclassMethods = Module.new do
|
|
204
308
|
|
205
309
|
end
|
206
310
|
|
207
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "
|
311
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "TXTSZ", potrubi_bootstrap_logger_fmt_kls(textMethods: textMethods))
|
208
312
|
|
209
313
|
textMethods.empty? || dynamic_define_methods_apply_texts(targetModule, *textMethods)
|
210
314
|
|
@@ -213,67 +317,73 @@ metaclassMethods = Module.new do
|
|
213
317
|
self
|
214
318
|
|
215
319
|
end
|
216
|
-
#=end
|
217
320
|
|
218
|
-
|
219
|
-
|
220
|
-
|
321
|
+
# do any of the method specification have a proc key?
|
322
|
+
# Implies pass whole method meth to proc and use result
|
323
|
+
# allow for logic in e.g. method text createion
|
324
|
+
# result must be array of method spec hashes
|
325
|
+
|
326
|
+
def dynamic_define_methods_apply_procs(targetModule, *specsNom, &specBlok)
|
327
|
+
eye = :ddm_apl_prcs
|
328
|
+
eyeTale = 'DDM APL PROCS'
|
221
329
|
|
222
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}< specs >#{
|
330
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}< specs >#{specsNom.class}< >#{specsNom}<")
|
223
331
|
|
224
|
-
|
332
|
+
specsVal = dynamic_define_methods_validate_specifications(*specsNom)
|
225
333
|
|
226
|
-
|
334
|
+
specsNrm = specsVal.map.with_index do | specNom, specNdx |
|
335
|
+
|
336
|
+
puts("#{eye} #{eyeTale} specNdx >#{specNdx}< specNom >#{specNom.class}< >#{specNom}<")
|
337
|
+
|
338
|
+
case
|
339
|
+
when specNom.has_key?(:proc) then
|
340
|
+
r = potrubi_bootstrap_mustbe_proc_or_croak(specNom[:proc], eye).call(specNom)
|
341
|
+
else
|
342
|
+
specNom
|
343
|
+
end
|
227
344
|
|
228
|
-
|
345
|
+
end.flatten.compact
|
346
|
+
|
347
|
+
dynamic_define_methods_validate_specifications(*specsNrm)
|
348
|
+
|
349
|
+
specsPrc = Kernel.block_given? ? specsNrm.map {|s| specBlok.call(s)} : specsNrm
|
350
|
+
|
351
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}< specsPrc >#{specsPrc.class}< >#{specsPrc.size}<")
|
352
|
+
|
353
|
+
specsPrc.each_with_index {|s,i| puts("#{eye} #{eyeTale} i >#{i}< s >#{s.class}< >#{s}<") }
|
354
|
+
|
355
|
+
potrubi_bootstrap_mustbe_array_or_croak(specsPrc, eye)
|
356
|
+
|
357
|
+
end
|
358
|
+
|
359
|
+
def dynamic_define_methods_apply_texts(targetModule, *methodSpecsNom, &dynBlok)
|
360
|
+
eye = :ddm_apl_txt
|
361
|
+
eyeTale = 'DDM APL TXTS'
|
229
362
|
|
230
|
-
|
363
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "targetModule >#{targetModule.class}< >#{targetModule}<", potrubi_bootstrap_logger_fmt_kls_size(specs: methodSpecsNom))
|
231
364
|
|
232
|
-
|
365
|
+
methodSpecs = dynamic_define_methods_validate_specifications(*methodSpecsNom)
|
366
|
+
|
367
|
+
begin
|
233
368
|
|
234
|
-
|
369
|
+
methodTexts = methodSpecs.map do | specHash |
|
235
370
|
|
236
|
-
|
237
|
-
|
371
|
+
#$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "BEG specHash >#{specHash.class}< >#{specHash}<\n\n\n")
|
372
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "BEG", potrubi_bootstrap_logger_fmt_kls_size(specHash: specHash))
|
238
373
|
|
239
|
-
|
374
|
+
potrubi_bootstrap_mustbe_hash_or_croak(specHash)
|
240
375
|
|
241
|
-
|
242
|
-
|
243
|
-
# Resolve any snippets
|
244
|
-
|
245
|
-
#methodSnipNom = potrubi_bootstrap_mustbe_string_or_croak(Potrubi::Mixin::TextSnippets.map_snippets_or_croak(:dynamic_methods, *methodText).flatten.compact.join)
|
246
|
-
methodSnippets = Potrubi::Mixin::TextSnippets.map_snippets_or_croak(:dynamic_methods, *methodText)
|
247
|
-
|
248
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "SNIP methodSnippets >#{methodSnippets.class}< >#{methodSnippets}<")
|
376
|
+
specEdit = specHash[:edit]
|
377
|
+
specSpec = specHash[:spec]
|
249
378
|
|
250
|
-
|
251
|
-
|
252
|
-
snipEdits = []
|
253
|
-
|
254
|
-
snipTexts = methodSnippets.inject([]) do | textList, snipItem |
|
255
|
-
|
256
|
-
###puts("\nSNIP ITEM >#{snipItem.class}< >#{snipItem}<")
|
257
|
-
|
258
|
-
textList << case snipItem
|
259
|
-
when Hash
|
260
|
-
snipEdits << snipItem[:edit] # collect any edits e.g. defaults
|
261
|
-
###potrubi_bootstrap_mustbe_string_or_croak(snipItem[:spec]) # return the text
|
262
|
-
snipItem[:spec]
|
263
|
-
when String then snipItem
|
264
|
-
else
|
265
|
-
potrubi_bootstrap_surprise_exception(methodTextNom, eye, "methodTextNom unexpected")
|
266
|
-
end
|
379
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "EDIT & SPEC specEdit >#{specEdit}< specSpec >#{specSpec.class}< >#{specSpec.class}<")
|
380
|
+
#$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "EDIT & SPEC specEdit >#{specEdit}< specSpec >#{specSpec.class}< >#{specSpec}<")
|
267
381
|
|
268
|
-
|
269
|
-
|
270
|
-
methodText = dynamic_apply_edits([snipEdits, methodEdit], snipTexts) # note order of edits
|
382
|
+
specText = dynamic_apply_edits(specEdit, specSpec) # note order of edits
|
271
383
|
|
272
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "FIN
|
384
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "FIN specEdit >#{specEdit}< specText >#{specText}<\n\n\n")
|
273
385
|
|
274
|
-
|
275
|
-
|
276
|
-
methodText
|
386
|
+
specText
|
277
387
|
|
278
388
|
end.flatten.compact.join("\n")
|
279
389
|
rescue Exception => e
|
@@ -282,6 +392,7 @@ metaclassMethods = Module.new do
|
|
282
392
|
end
|
283
393
|
|
284
394
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger(eye, eyeTale, "METHODS targetModule >#{targetModule.class}< >#{targetModule}< methodTexts >#{methodTexts.class}< >\n#{methodTexts}\n<")
|
395
|
+
###puts("#{eye} #{eyeTale} METHODS targetModule >#{targetModule.class}< >#{targetModule}< methodTexts >#{methodTexts.class}< >\n#{methodTexts}\n<")
|
285
396
|
|
286
397
|
methodTexts && targetModule.module_eval(methodTexts)
|
287
398
|
|
@@ -290,10 +401,8 @@ metaclassMethods = Module.new do
|
|
290
401
|
self
|
291
402
|
|
292
403
|
end
|
293
|
-
#=end
|
294
404
|
|
295
405
|
end
|
296
|
-
#=end
|
297
406
|
|
298
407
|
module Potrubi
|
299
408
|
module Mixin
|
@@ -307,9 +416,8 @@ Potrubi::Mixin::Dynamic.__send__(:include, metaclassMethods) # Instance Methods
|
|
307
416
|
|
308
417
|
# must be after dynamic is up
|
309
418
|
|
310
|
-
requireList = %w(
|
419
|
+
requireList = %w(snippet-manager)
|
311
420
|
requireList.each {|r| require_relative "#{r}"}
|
312
421
|
|
313
422
|
__END__
|
314
423
|
|
315
|
-
|