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
@@ -0,0 +1,731 @@
|
|
1
|
+
|
2
|
+
# potrubi contract dsl
|
3
|
+
|
4
|
+
# to ease the creation of contracts, accessors, etc in class bodies
|
5
|
+
|
6
|
+
# Uses conventions for names etc dedined by (in) contract mixin
|
7
|
+
|
8
|
+
#require_relative '../../bootstrap'
|
9
|
+
|
10
|
+
requireList = %w(super ../mixin/util)
|
11
|
+
requireList.each {|r| require_relative "#{r}"}
|
12
|
+
require "potrubi/klass/syntax/braket"
|
13
|
+
|
14
|
+
classContent = Module.new do
|
15
|
+
|
16
|
+
include Potrubi::Bootstrap
|
17
|
+
include Potrubi::Mixin::Util
|
18
|
+
|
19
|
+
attr_accessor :key, :value, :spec, :edit, :blok, :key_names, :default
|
20
|
+
|
21
|
+
def assert_self
|
22
|
+
eye = 'DSLCtx:assert_self'
|
23
|
+
eyeTale = to_s
|
24
|
+
|
25
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale)
|
26
|
+
|
27
|
+
ctxSelf = self
|
28
|
+
ctxType = type
|
29
|
+
|
30
|
+
case ctxType
|
31
|
+
when NilClass then
|
32
|
+
potrubi_bootstrap_surprise_exception(ctxType, eye, "self >#{self} ctxType can not be nil")
|
33
|
+
else
|
34
|
+
|
35
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_beg(eye, 'MAKE VERB', eyeTale, "ctxType >#{ctxType}<")
|
36
|
+
|
37
|
+
ctxSpec = spec
|
38
|
+
(ctxEdit = edit) && potrubi_boostrap_mustbe_hash_or_croak(ctxEdit, eye)
|
39
|
+
(ctxBlok = blok) && potrubi_boostrap_mustbe_proc_or_croak(ctxBlok, eye)
|
40
|
+
|
41
|
+
(ctxBldr = builder) && potrubi_bootstrap_mustbe_module_or_croak(ctxBldr, eye)
|
42
|
+
|
43
|
+
# target for contract
|
44
|
+
(ctxTgt = target) && potrubi_bootstrap_mustbe_module_or_croak(ctxTgt, eye)
|
45
|
+
|
46
|
+
# builder_data is the method name in the builder
|
47
|
+
|
48
|
+
(ctxBldrMth = builder_data) && potrubi_bootstrap_mustbe_symbol_or_croak(ctxBldrMth, eye)
|
49
|
+
|
50
|
+
ctxDesc = express_or_croak
|
51
|
+
|
52
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, 'DESC VERB', eyeTale, potrubi_bootstrap_logger_fmt_who(ctxBldrMth: ctxBldrMth, ctxEdit: ctxEdit, ctxSpec: ctxSpec, ctxBlok: ctxBlok, ctxDesc: ctxDesc, ctxTgt: ctxTgt, ctxBldr: ctxBldr))
|
53
|
+
|
54
|
+
ctxBldr.__send__(ctxBldrMth, ctxTgt, ctxDesc, ctxSpec, &ctxBlok)
|
55
|
+
|
56
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_fin(eye, 'MADE VERB', eyeTale)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale)
|
61
|
+
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_s
|
66
|
+
@to_s ||= potrubi_bootstrap_logger_fmt(potrubi_bootstrap_logger_instance_telltale('DSLCtx'), potrubi_bootstrap_logger_fmt(n: name))
|
67
|
+
end
|
68
|
+
|
69
|
+
# Find Methods
|
70
|
+
# ############
|
71
|
+
|
72
|
+
def find_key_type_or_croak
|
73
|
+
potrubi_bootstrap_mustbe_not_nil_or_croak(key)
|
74
|
+
end
|
75
|
+
|
76
|
+
def find_value_type_or_croak
|
77
|
+
potrubi_bootstrap_mustbe_not_nil_or_croak(value)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Contract Descriptions
|
81
|
+
# #####################
|
82
|
+
|
83
|
+
# This *only* makes the immediate (self) contract's description
|
84
|
+
|
85
|
+
def make_contract_description_or_croak(descArgs=nil, &descBlok)
|
86
|
+
eye = :'DSLCtx::m_ctx_desc'
|
87
|
+
|
88
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(descArgs: descArgs, descBlok: descBlok))
|
89
|
+
|
90
|
+
contractType = type
|
91
|
+
|
92
|
+
descContract = case contractType
|
93
|
+
when NilClass then nil
|
94
|
+
else
|
95
|
+
contractHandler = case contractType
|
96
|
+
#when Symbol then find_type_handler_or_default_or_croak(contractType)
|
97
|
+
when Symbol then find_type_handler_or_croak(contractType)
|
98
|
+
when String then 'make_contract_description_default_or_croak'
|
99
|
+
else
|
100
|
+
potrubi_bootstrap_surprise_exception(contractType, eye, "contractType is what?")
|
101
|
+
end
|
102
|
+
|
103
|
+
__send__(contractHandler, descArgs, &descBlok)
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(descContract: descContract, descArgs: descArgs, descBlok: descBlok))
|
108
|
+
|
109
|
+
descContract
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# Contract Types
|
114
|
+
# ##############
|
115
|
+
|
116
|
+
def type_handlers
|
117
|
+
@type_handlers ||=
|
118
|
+
begin
|
119
|
+
|
120
|
+
baseHandlers = [:default,
|
121
|
+
# :any,
|
122
|
+
:proc,
|
123
|
+
:enumerator,
|
124
|
+
:string,
|
125
|
+
:symbol,
|
126
|
+
:array,
|
127
|
+
:hash,
|
128
|
+
:fixnum,
|
129
|
+
:file,
|
130
|
+
:directory
|
131
|
+
].each_with_object({}) {|a, h| h[a] = :default }
|
132
|
+
|
133
|
+
baseHandlers.merge(
|
134
|
+
{
|
135
|
+
contract_collection: :contract_collection,
|
136
|
+
contract_2d: :contract_collection,
|
137
|
+
|
138
|
+
contract_collection_with_nil_values: :contract_collection_with_nil_values,
|
139
|
+
contract_2d_with_nil_values: :contract_collection_with_nil_values,
|
140
|
+
|
141
|
+
typed_collection: :typed_collection,
|
142
|
+
typed_hash: :typed_collection,
|
143
|
+
|
144
|
+
typed_collection_with_nil_values: :typed_collection_with_nil_values,
|
145
|
+
#typed_collection_with_nil_values: :typed_collection, # TESTING
|
146
|
+
typed_2d_with_nil_values: :typed_collection_with_nil_values,
|
147
|
+
|
148
|
+
typed_array: :typed_array,
|
149
|
+
|
150
|
+
collection_with_keys: :collection_with_keys,
|
151
|
+
hash_with_keys: :collection_with_keys,
|
152
|
+
|
153
|
+
typed_collection_with_keys: :typed_collection_with_keys,
|
154
|
+
typed_hash_with_keys: :typed_hash_with_keys,
|
155
|
+
|
156
|
+
}).each_with_object({}) {|(k,v), h| h[k] = "make_contract_description_#{v}_or_croak".to_sym }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
# Contract Handlers
|
162
|
+
# #################
|
163
|
+
|
164
|
+
def make_contract_description_default_or_croak(descArgs=nil, &descBlok)
|
165
|
+
eye = :'DSLCtx::m_ctx_desc_dflt'
|
166
|
+
|
167
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(descArgs: descArgs, descBlok: descBlok))
|
168
|
+
|
169
|
+
descContract = {name => type}
|
170
|
+
|
171
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, 'CHECK', 'KEY', 'NAME', potrubi_bootstrap_logger_fmt_who(key_name: key_name))
|
172
|
+
|
173
|
+
descContract =
|
174
|
+
if (r = key_name) then
|
175
|
+
#{name => {edit: {MUSTBE_KEY_NAME: r}}}
|
176
|
+
{name => {edit: {MUSTBE_KEY_NAME: r}, other: {type: type, key_name: r}}}
|
177
|
+
else
|
178
|
+
{name => type}
|
179
|
+
end
|
180
|
+
|
181
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContract: descContract, descArgs: descArgs, descBlok: descBlok))
|
182
|
+
|
183
|
+
descContract
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
def make_contract_description_typed_collection_or_croak(descArgs=nil, &descBlok)
|
188
|
+
eye = :'DSLCtx::m_ctx_desc_type_coll'
|
189
|
+
|
190
|
+
keyType = find_key_type_or_croak
|
191
|
+
valueType = find_value_type_or_croak
|
192
|
+
|
193
|
+
descContracts = make_contract_description_top_blok_or_croak do | descArgs |
|
194
|
+
{name => {spec: :method_mustbe_is_value_typed_collection, edit: {KEY_TYPE: keyType, VALUE_TYPE: valueType}}}
|
195
|
+
end
|
196
|
+
|
197
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
198
|
+
|
199
|
+
descContracts
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
def make_contract_description_typed_collection_with_nil_values_or_croak(descArgs=nil, &descBlok)
|
204
|
+
eye = :'DSLCtx::m_ctx_desc_type_coll_with_nil_values'
|
205
|
+
|
206
|
+
keyType = find_key_type_or_croak
|
207
|
+
valueType = find_value_type_or_croak
|
208
|
+
|
209
|
+
descContracts = make_contract_description_top_blok_or_croak do | descArgs |
|
210
|
+
{name => {spec: :method_mustbe_is_value_typed_collection, edit: {KEY_TYPE: keyType, VALUE_TYPE: valueType, VALUE_IS_NIL_RESULT: 'true'}}}
|
211
|
+
end
|
212
|
+
|
213
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
214
|
+
|
215
|
+
descContracts
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
def make_contract_description_typed_collection_with_keys_or_croak(descArgs=nil, &descBlok)
|
220
|
+
eye = :'DSLCtx::m_ctx_desc_type_coll_with_keys'
|
221
|
+
|
222
|
+
keyType = find_key_type_or_croak
|
223
|
+
valueType = find_value_type_or_croak
|
224
|
+
keyNames = key_names
|
225
|
+
|
226
|
+
descContracts = make_contract_description_top_blok_or_croak do | descArgs |
|
227
|
+
{name => {spec: :method_mustbe_is_value_typed_collection_with_keys, edit: {KEY_TYPE: keyType, VALUE_TYPE: valueType, KEY_NAMES: keyNames}}}
|
228
|
+
end
|
229
|
+
|
230
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
231
|
+
|
232
|
+
descContracts
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
def make_contract_description_contract_collection_or_croak(descArgs=nil, &descBlok)
|
237
|
+
eye = :'DSLCtx::m_ctx_desc_ctx_coll'
|
238
|
+
|
239
|
+
descContracts = make_contract_description_is_value_collection_or_croak(descArgs) do | key, contract, braKet |
|
240
|
+
|
241
|
+
# any explicit key?
|
242
|
+
keyName = potrubi_util_find_hash_keys(contract, :other, :key_name)
|
243
|
+
|
244
|
+
braKet.new_statement.push(
|
245
|
+
'((r = testValue[:',
|
246
|
+
keyName || key,
|
247
|
+
']).nil? ? false : ',
|
248
|
+
'is_value_',
|
249
|
+
key,
|
250
|
+
'?(r))',
|
251
|
+
' && '
|
252
|
+
)
|
253
|
+
|
254
|
+
|
255
|
+
end
|
256
|
+
|
257
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
258
|
+
|
259
|
+
descContracts
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
def make_contract_description_contract_collection_with_nil_values_or_croak(descArgs=nil, &descBlok)
|
264
|
+
eye = :'DSLCtx::m_ctx_desc_ctx_coll_with_nil_values'
|
265
|
+
|
266
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(descArgs: descArgs, descBlok: descBlok))
|
267
|
+
|
268
|
+
descContracts = make_contract_description_is_value_collection_or_croak(descArgs) do | key, contract, braKet |
|
269
|
+
|
270
|
+
# any explcit key name?
|
271
|
+
#keyName = potrubi_util_find_hash_keys_or_croak(contract, :other, :key_name)
|
272
|
+
keyName = potrubi_util_find_hash_keys(contract, :other, :key_name)
|
273
|
+
|
274
|
+
r = braKet.new_statement.push(
|
275
|
+
'((r = testValue[:',
|
276
|
+
keyName || key,
|
277
|
+
']).nil? ? true : ',
|
278
|
+
'is_value_',
|
279
|
+
key,
|
280
|
+
'?(r))',
|
281
|
+
' && '
|
282
|
+
)
|
283
|
+
|
284
|
+
r
|
285
|
+
end
|
286
|
+
|
287
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
288
|
+
|
289
|
+
descContracts
|
290
|
+
|
291
|
+
end
|
292
|
+
|
293
|
+
def make_contract_description_collection_with_keys_or_croak(descArgs=nil, &descBlok)
|
294
|
+
eye = :'DSLCtx::m_ctx_desc_coll_w_keys'
|
295
|
+
|
296
|
+
keyNames = potrubi_bootstrap_mustbe_not_nil_or_croak(key_names, eye)
|
297
|
+
|
298
|
+
descContracts = make_contract_description_top_blok_or_croak do | descArgs |
|
299
|
+
{name => {spec: :method_mustbe_is_value_collection_with_keys, edit: {KEY_NAMES: keyNames}}}
|
300
|
+
end
|
301
|
+
|
302
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
303
|
+
|
304
|
+
descContracts
|
305
|
+
|
306
|
+
end
|
307
|
+
|
308
|
+
def make_contract_description_typed_array_or_croak(descArgs=nil, &descBlok)
|
309
|
+
eye = :'DSLCtx::m_ctx_desc_typed_array'
|
310
|
+
|
311
|
+
valueType = potrubi_bootstrap_mustbe_not_nil_or_croak(value, eye)
|
312
|
+
|
313
|
+
descContracts = make_contract_description_top_blok_or_croak do | descArgs |
|
314
|
+
{name => {spec: :method_mustbe_is_value_typed_array, edit: {VALUE_TYPE: valueType}}}
|
315
|
+
end
|
316
|
+
|
317
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
318
|
+
|
319
|
+
descContracts
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
# Contract Handler Support Methods
|
324
|
+
# ################################
|
325
|
+
|
326
|
+
def make_contract_description_top_blok_or_croak(descArgs=nil, &descBlok)
|
327
|
+
eye = :'DSLCtx::m_ctx_desc_top_blok'
|
328
|
+
|
329
|
+
descName = name
|
330
|
+
|
331
|
+
potrubi_bootstrap_mustbe_proc_or_croak(descBlok, eye)
|
332
|
+
|
333
|
+
descContract = descBlok.call(descArgs)
|
334
|
+
|
335
|
+
$DEBUG_POTRUBI_BOOTSTRAP && show_verb_expression_or_croak(descContract, "TOP BLOK descName >#{descName}< DESC CONTRACTS")
|
336
|
+
|
337
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContract: descContract, descArgs: descArgs, descBlok: descBlok))
|
338
|
+
|
339
|
+
descContract
|
340
|
+
|
341
|
+
end
|
342
|
+
|
343
|
+
|
344
|
+
def make_contract_description_is_value_collection_or_croak(descArgs=nil, &descBlok)
|
345
|
+
eye = :'DSLCtx::m_ctx_desc_is_value_col'
|
346
|
+
|
347
|
+
descsImmedSubverbs = find_subverbs_expression_or_croak
|
348
|
+
|
349
|
+
descContract = make_contract_description_is_value_method_or_croak(name, descsImmedSubverbs, &descBlok)
|
350
|
+
|
351
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContract: descContract, descArgs: descArgs, descBlok: descBlok))
|
352
|
+
|
353
|
+
descContract
|
354
|
+
|
355
|
+
end
|
356
|
+
|
357
|
+
# Takes name of the is_value method, the subcontracts,
|
358
|
+
# and build an is_value method to test all the values
|
359
|
+
# Note the test is buildt by the provided blok
|
360
|
+
|
361
|
+
def make_contract_description_is_value_method_or_croak(descName, descCtxs, &descBlok)
|
362
|
+
eye = :'DSLCtx::m_ctx_desc_is_value_mth'
|
363
|
+
|
364
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(descName: descName, descCtxs: descCtxs, descBlok: descBlok))
|
365
|
+
|
366
|
+
potrubi_bootstrap_mustbe_hash_or_croak(descCtxs, eye, 'descCts failed contract')
|
367
|
+
potrubi_bootstrap_mustbe_proc_or_croak(descBlok, eye)
|
368
|
+
|
369
|
+
braketKls = Potrubi::Klass::Syntax::Braket
|
370
|
+
|
371
|
+
braketMethod = braketKls.new_method
|
372
|
+
|
373
|
+
braketDefBeg = braketKls.new_statement.push('def is_value_', descName, '?(testValue)')
|
374
|
+
|
375
|
+
braketCollection = braketKls.new_statement.push('testValue.is_a?(Hash) &&')
|
376
|
+
|
377
|
+
braketItems = descCtxs.map { | key, contract | descBlok.call(key, contract, braketKls) }
|
378
|
+
|
379
|
+
braketResult = braketKls.new_statement.push('testValue')
|
380
|
+
|
381
|
+
braketDefEnd = braketKls.new_statement.push('end')
|
382
|
+
|
383
|
+
braketMethod.push(braketDefBeg,
|
384
|
+
braketCollection,
|
385
|
+
braketItems,
|
386
|
+
braketResult,
|
387
|
+
braketDefEnd,
|
388
|
+
)
|
389
|
+
|
390
|
+
descText = braketMethod.to_s
|
391
|
+
|
392
|
+
descContract = {descName => {spec: descText}}
|
393
|
+
|
394
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(descName: descName, descContract: descContract))
|
395
|
+
|
396
|
+
potrubi_bootstrap_mustbe_hash_or_croak(descContract, eye)
|
397
|
+
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
402
|
+
module Potrubi
|
403
|
+
class DSL
|
404
|
+
class Contract < Potrubi::DSL::Super
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
Potrubi::DSL::Contract.__send__(:include, classContent) # Instance Methods
|
410
|
+
|
411
|
+
__END__
|
412
|
+
|
413
|
+
Potrubi::DSL::Contract.extend(classMethods) # Class Methods
|
414
|
+
|
415
|
+
__END__
|
416
|
+
|
417
|
+
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
# def make_contract_descriptions_or_croak(descArgs=nil, &descBlok)
|
442
|
+
# eye = :'DSLCtx::m_ctx_descs'
|
443
|
+
|
444
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, to_s, potrubi_bootstrap_logger_fmt_who(subverbs: get_subverbs.size, descArgs: descArgs, descBlok: descBlok))
|
445
|
+
|
446
|
+
# ###STOPHEREMAKECONTRACTDESCSENTR
|
447
|
+
|
448
|
+
# descSubverbs = nil
|
449
|
+
# #show_subverbs(eye, "MAKE SUBCTX DESCS #{to_s}")
|
450
|
+
# #descsSubverbs = make_subcontracts_descriptions_or_croak(descArgs, &descBlok)
|
451
|
+
# #show_subverbs(eye, "MADE SUBCTX DESCS #{to_s}")
|
452
|
+
|
453
|
+
# #descContract = type.nil? ? nil : make_contract_description_or_croak(descArgs, &descBlok)
|
454
|
+
# descContracts = case type
|
455
|
+
# when NilClass then find_subverbs_description_or_croak(descArgs, &descBlok)
|
456
|
+
# else
|
457
|
+
# find_contract_description_or_croak(descArgs, &descBlok)
|
458
|
+
# end
|
459
|
+
|
460
|
+
|
461
|
+
# show_verb_expression_or_croak(descContracts, eye, "M CTX DESCS descName >#{name}<")
|
462
|
+
|
463
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, to_s, potrubi_bootstrap_logger_fmt_who(descContracts: descContracts, descArgs: descArgs, descBlok: descBlok))
|
464
|
+
|
465
|
+
# potrubi_bootstrap_mustbe_hash_or_croak(descContracts, eye)
|
466
|
+
|
467
|
+
# #STOPHEREMAKECONTRACTDESCSEXIT
|
468
|
+
# end
|
469
|
+
# def make_subcontracts_descriptions_or_croak(descArgs=nil, &descBlok)
|
470
|
+
# eye = :'DSLCtx::m_subctxs_descs'
|
471
|
+
|
472
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, to_s, potrubi_bootstrap_logger_fmt_who(subverbs: get_subverbs.size, descArgs: descArgs, descBlok: descBlok))
|
473
|
+
|
474
|
+
# ###STOPHEREMAKECONTRACTDESCSENTR
|
475
|
+
|
476
|
+
# #descSubverbs = nil
|
477
|
+
# #show_subverbs(eye, "MAKE SUBCTX DESCS #{to_s}")
|
478
|
+
|
479
|
+
# descsSubverbs = case
|
480
|
+
# when has_subverbs? then get_subverbs.map {|c| c.make_contract_descriptions_or_croak(descArgs, &descBlok) }.flatten.compact
|
481
|
+
# else
|
482
|
+
# nil
|
483
|
+
# end
|
484
|
+
|
485
|
+
# #show_subverbs(eye, "MADE SUBCTX DESCS #{to_s}")
|
486
|
+
|
487
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, to_s, potrubi_bootstrap_logger_fmt_who(descsSubverbs: descsSubverbs, descArgs: descArgs, descBlok: descBlok))
|
488
|
+
|
489
|
+
# descsSubverbs && potrubi_bootstrap_mustbe_array_or_croak(descsSubverbs, eye)
|
490
|
+
|
491
|
+
# #STOPHEREMAKECONTRACTDESCSEXIT
|
492
|
+
# end
|
493
|
+
|
494
|
+
# # merge the individual contract descs into a single hash
|
495
|
+
# # BUT check for duplicate keys
|
496
|
+
|
497
|
+
# def reduce_contract_descriptions_or_croak(*descContracts, &descBlok)
|
498
|
+
# eye = :'DSLCtx::rdc_ctx_descs'
|
499
|
+
# descReduce = potrubi_util_reduce_hashes_or_croak(*descContracts) {|k, oldV, newV| potrubi_bootstrap_duplicate_exception(k, eye, "subcontract name >#{k} seen twice") }
|
500
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, to_s, potrubi_bootstrap_logger_fmt_who(descReduce: descReduce, descContracts: descContracts, descBlok: descBlok))
|
501
|
+
# descReduce && potrubi_bootstrap_mustbe_hash_or_croak(descReduce)
|
502
|
+
# end
|
503
|
+
|
504
|
+
# # merge the individual contract into a single hash
|
505
|
+
|
506
|
+
# def make_subcontracts_description_or_croak(descArgs=nil, &descBlok)
|
507
|
+
# eye = :'DSLCtx::m_subctxs_desc'
|
508
|
+
# r = make_subcontracts_descriptions_or_croak(descArgs, &descBlok)
|
509
|
+
# descSubverbs = reduce_contract_descriptions_or_croak(*r)
|
510
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, to_s, potrubi_bootstrap_logger_fmt_who(descSubverbs: descSubverbs, descArgs: descArgs, descBlok: descBlok))
|
511
|
+
# descSubverbs
|
512
|
+
# end
|
513
|
+
|
514
|
+
|
515
|
+
# # Diagnostics
|
516
|
+
# # ###########
|
517
|
+
|
518
|
+
|
519
|
+
# def show(*tellTales)
|
520
|
+
# eye = :show
|
521
|
+
|
522
|
+
# #if $DEBUG_POTRUBI_BOOTSTRAP then
|
523
|
+
# ##cummulative_tellTale = potrubi_bootstrap_logger_fmt(*tellTales, potrubi_bootstrap_logger_fmt(name: name, type: type))
|
524
|
+
# cummulative_tellTale = potrubi_bootstrap_logger_fmt(*tellTales, to_s)
|
525
|
+
# case
|
526
|
+
# when has_subverbs? then show_subverbs(cummulative_tellTale)
|
527
|
+
# else
|
528
|
+
# potrubi_bootstrap_logger_ms(eye, cummulative_tellTale)
|
529
|
+
# end
|
530
|
+
# #end
|
531
|
+
|
532
|
+
# self
|
533
|
+
|
534
|
+
# end
|
535
|
+
|
536
|
+
|
537
|
+
# classMethods = Module.new do
|
538
|
+
|
539
|
+
# def new_contract(dslArgs=nil, &dslBlok) # class method
|
540
|
+
# eye = :'DSLCtx::KLS new_cxt'
|
541
|
+
# #potrubi_bootstrap_mustbe_symbol_or_croak(dslAttr, eye, "dslAttr is what?")
|
542
|
+
# newContract = self.new(dslArgs, &dslBlok)
|
543
|
+
# #$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(newContract: newContract), potrubi_bootstrap_logger_fmt_who(dslAttr: dslAttr, dslArgs: dslArgsNrm, dslBlok: dslBlok))
|
544
|
+
# newContract
|
545
|
+
# ###STOPHERENEWCONTRACTEXIT
|
546
|
+
# end
|
547
|
+
# end
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
# def make_contract_description_accessor_or_croak(descArgs=nil, &descBlok)
|
555
|
+
# eye = :'DSLCtx::m_ctx_desc_acc'
|
556
|
+
|
557
|
+
# #$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(descArgs: descArgs, descBlok: descBlok))
|
558
|
+
|
559
|
+
# #descContract = {name => type}
|
560
|
+
# #descContract = {name => {edit: {ACCESSOR_DEFAULT: 9099}}}
|
561
|
+
|
562
|
+
# descContract = case
|
563
|
+
# when (descDefault = default) then
|
564
|
+
# #descDefault = descArgs.default
|
565
|
+
# descDefaultText = case descDefault
|
566
|
+
# when NilClass then 'nil'
|
567
|
+
# when String then "'#{descDefault}'" # need quotes
|
568
|
+
# when Symbol then ":#{descDefault}" # need to supply :
|
569
|
+
# else
|
570
|
+
# descDefault.to_s
|
571
|
+
# end
|
572
|
+
# {name => {edit: {ACCESSOR_DEFAULT: descDefaultText}, spec: type}}
|
573
|
+
|
574
|
+
# else
|
575
|
+
# {name => type}
|
576
|
+
# end
|
577
|
+
|
578
|
+
|
579
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(descContract: descContract, descArgs: descArgs, descBlok: descBlok))
|
580
|
+
|
581
|
+
# descContract
|
582
|
+
# #STOPHEREMAKECTXDESCACCEXIT
|
583
|
+
# end
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
# # Initialization
|
629
|
+
# # ##############
|
630
|
+
|
631
|
+
# def initialize(dslArgs=nil, &dslBlok)
|
632
|
+
# eye = :'DSLCtx::i'
|
633
|
+
|
634
|
+
# dslAttr = 'wantbeused'
|
635
|
+
|
636
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(dslArgs: dslArgs, dslBlok: dslBlok))
|
637
|
+
|
638
|
+
# #STOPHEREINITDSL
|
639
|
+
|
640
|
+
# case dslArgs
|
641
|
+
# when NilClass then nil
|
642
|
+
# when Hash then potrubi_bootstrap_mustbe_hash_or_croak(dslArgs, eye).each {|k, v| __send__("#{k}=", v) }
|
643
|
+
# ###when Symbol then self.type = dslArgs # syntax sugar for the contract type
|
644
|
+
# else
|
645
|
+
# potrubi_bootstrap_surpirse_exception(dslArgs, eye, "dslArgs is what?")
|
646
|
+
# end
|
647
|
+
|
648
|
+
# Kernel.block_given? && instance_eval(&dslBlok)
|
649
|
+
|
650
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(subverbs: get_subverbs.size, dslArgs: dslArgs, dslBlok: dslBlok))
|
651
|
+
|
652
|
+
# end
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
|
657
|
+
# def zzznew_subcontract(dslAttr, dslArgsNom=nil, &dslBlok)
|
658
|
+
# eye = :'DSLCtx::new_sub_cxt'
|
659
|
+
# #potrubi_bootstrap_mustbe_symbol_or_croak(dslAttr, eye, "dslAttr is what?")
|
660
|
+
# dslArgsNrm = case dslArgsNom
|
661
|
+
# when NilClass, Hash then dslArgsNom
|
662
|
+
# when Symbol then {type: dslArgsNom} # syntax sugar for type
|
663
|
+
# else
|
664
|
+
# potrubi_bootstrap_surprise_exception(dslArgsNom, eye, "dslArgsNom is what?")
|
665
|
+
# end
|
666
|
+
# subContract = self.class.new_contract(potrubi_util_merge_hashes_or_croak(dslArgsNrm, {name: dslAttr}), &dslBlok)
|
667
|
+
|
668
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(subContract: subContract), potrubi_bootstrap_logger_fmt_who(dslAttr: dslAttr, dslArgs: dslArgsNrm, dslBlok: dslBlok))
|
669
|
+
|
670
|
+
# subContract
|
671
|
+
# end
|
672
|
+
|
673
|
+
# def xxxaccessor_with_contract(dslAttr, dslArgs=nil, &dslBlok)
|
674
|
+
# eye = :'DSLCtx::acc_w_ctx'
|
675
|
+
|
676
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(dslAttr: dslAttr, dslArgs: dslArgs, dslBlok: dslBlok))
|
677
|
+
|
678
|
+
# dslDefs = {variant: :accessor, name: dslAttr, spec: :package_accessor_with_contract}
|
679
|
+
|
680
|
+
# newContract = make_and_add_new_contract(dslDefs, dslArgs, &dslBlok)
|
681
|
+
|
682
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(newContract: newContract, dslAttr: dslAttr, dslArgs: dslArgs, dslBlok: dslBlok))
|
683
|
+
|
684
|
+
# newContract
|
685
|
+
|
686
|
+
# end
|
687
|
+
|
688
|
+
# def zzzassert
|
689
|
+
# eye = :'DSLCtx::assert'
|
690
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(self: self))
|
691
|
+
# assert_self
|
692
|
+
# subverbs.each {|v| v.assert}
|
693
|
+
|
694
|
+
# dslVerbs = dslVerb.subverbs
|
695
|
+
|
696
|
+
# #puts("\n\n\n#{eye} MADE VERBS dslVerbs >#{dslVerbs}<")
|
697
|
+
# dslVerb.flatten.each_with_index {|v, i| puts("\n#{eye} INST VERBS >#{i}< >#{v.class}< >#{v}<") }
|
698
|
+
|
699
|
+
|
700
|
+
# #STOPHEREMADECTXS
|
701
|
+
|
702
|
+
# dslVerb.flatten.each_with_index do | ctx, ndx |
|
703
|
+
|
704
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_beg(eye, 'MAKE VERB', potrubi_bootstrap_logger_fmt_who(ndx: ndx, ctx: ctx))
|
705
|
+
|
706
|
+
# (ctxVariant = ctx.variant) &&
|
707
|
+
# begin
|
708
|
+
|
709
|
+
# potrubi_bootstrap_mustbe_symbol_or_croak(ctxVariant, eye)
|
710
|
+
|
711
|
+
# ctxSpec = ctx.spec
|
712
|
+
# (ctxEdit = ctx.edit) && potrubi_boostrap_mustbe_hash_or_croak(ctxEdit, eye)
|
713
|
+
# (ctxBlok = ctx.blok) && potrubi_boostrap_mustbe_proc_or_croak(ctxBlok, eye)
|
714
|
+
|
715
|
+
# ctxRecipe = "recipe_variant_#{ctxVariant}"
|
716
|
+
|
717
|
+
# ctxDesc = ctx.make_verb_description_or_croak
|
718
|
+
|
719
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, 'DESC VERB', potrubi_bootstrap_logger_fmt_who(ctxRecipe: ctxRecipe, ctxEdit: ctxEdit, ctxSpec: ctxSpec, ctxBlok: ctxBlok, ctxDesc: ctxDesc))
|
720
|
+
# __send__(ctxRecipe, dslTarget, ctxDesc, ctxSpec, &ctxBlok)
|
721
|
+
|
722
|
+
# end
|
723
|
+
|
724
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_fin(eye, 'MADE VERB', potrubi_bootstrap_logger_fmt_who(ndx: ndx, ctx: ctx))
|
725
|
+
|
726
|
+
# end
|
727
|
+
|
728
|
+
|
729
|
+
# $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(self: self))
|
730
|
+
# self
|
731
|
+
# end
|