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
data/lib/potrubi/mixin/script.rb
CHANGED
@@ -3,9 +3,6 @@
|
|
3
3
|
|
4
4
|
require_relative '../core'
|
5
5
|
|
6
|
-
#requireList = %w(bootstrap)
|
7
|
-
#requireList.each {|r| require_relative "#{r}"}
|
8
|
-
|
9
6
|
mixinContent = Module.new do
|
10
7
|
|
11
8
|
include Potrubi::Bootstrap
|
@@ -13,7 +10,6 @@ mixinContent = Module.new do
|
|
13
10
|
# Script Methods
|
14
11
|
# ##############
|
15
12
|
|
16
|
-
#=begin
|
17
13
|
def find_script_name_or_croak(scriptPath=$0)
|
18
14
|
File.basename(scriptPath, ".*")
|
19
15
|
end
|
@@ -46,7 +42,6 @@ mixinContent = Module.new do
|
|
46
42
|
def find_script_config_directory_or_croak(dirName='config', scriptPath=$0)
|
47
43
|
find_script_peer_directory_or_croak(dirName, scriptPath)
|
48
44
|
end
|
49
|
-
#=end
|
50
45
|
|
51
46
|
end
|
52
47
|
|
@@ -1,9 +1,71 @@
|
|
1
1
|
|
2
|
-
# potrubi text snippets
|
2
|
+
# potrubi method text snippets
|
3
3
|
|
4
|
-
# methods dictionary
|
4
|
+
# dynamic methods dictionary
|
5
5
|
|
6
|
+
# Procs
|
6
7
|
|
8
|
+
Proc.new do
|
9
|
+
|
10
|
+
isvaluecontractcollectionwithnilvaluesProc = ->(spec) {
|
11
|
+
eye = :'is_val_con_col'
|
12
|
+
|
13
|
+
require 'potrubi/klass/syntax/braket'
|
14
|
+
|
15
|
+
targetModule = potrubi_bootstrap_mustbe_module_or_croak(spec[:target], eye)
|
16
|
+
|
17
|
+
specEdit = potrubi_bootstrap_mustbe_hash_or_croak(spec[:edit], eye)
|
18
|
+
|
19
|
+
mustbeContracts = potrubi_bootstrap_mustbe_hash_or_croak(specEdit[:VALUE_CONTRACTS], eye, 'CONTRACT_RECIPES not hash')
|
20
|
+
|
21
|
+
braketKls = Potrubi::Klass::Syntax::Braket
|
22
|
+
|
23
|
+
braketMethod = braketKls.new_method
|
24
|
+
|
25
|
+
braketDefBeg = braketKls.new_statement.push('def is_value_MUSTBE_NAME?(testValue)')
|
26
|
+
|
27
|
+
braketCollection = braketKls.new_statement.push('testValue.is_a?(Hash) &&')
|
28
|
+
|
29
|
+
braketItems = mustbeContracts.map do | key, contract |
|
30
|
+
|
31
|
+
# if value is nil don't test
|
32
|
+
|
33
|
+
braketKls.new_statement.push(
|
34
|
+
'((r = testValue[:',
|
35
|
+
key,
|
36
|
+
']) ? ',
|
37
|
+
'is_value_',
|
38
|
+
key,
|
39
|
+
'?(r) : true)',
|
40
|
+
' && '
|
41
|
+
)
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
braketResult = braketKls.new_statement.push('testValue')
|
46
|
+
|
47
|
+
braketDefEnd = braketKls.new_statement.push('end')
|
48
|
+
|
49
|
+
braketMethod.push(braketDefBeg,
|
50
|
+
braketCollection,
|
51
|
+
braketItems,
|
52
|
+
braketResult,
|
53
|
+
braketDefEnd,
|
54
|
+
)
|
55
|
+
|
56
|
+
specText = braketMethod.to_s
|
57
|
+
|
58
|
+
# Generate the contracts for the allowed values
|
59
|
+
Potrubi::Mixin::ContractRecipes.recipe_mustbes(targetModule, mustbeContracts)
|
60
|
+
|
61
|
+
{edit: specEdit, spec: specText}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
# Texts
|
7
69
|
|
8
70
|
mustbeMethodOneArgText = <<-'ENDOFMUSTBESCALARMETHOD'
|
9
71
|
def mustbe_MUSTBE_NAME_or_croak(testValue, *tellTales)
|
@@ -17,7 +79,6 @@
|
|
17
79
|
Kernel.block_given? ? r.map {|v| procBlok.call(v) } : r
|
18
80
|
end;
|
19
81
|
def mustbe_MUSTBE_NAME_key_or_nil_with_proc_or_croak(testValue, keyName, *tellTales, &procBlok)
|
20
|
-
#(r = is_value_key?(testValue, keyName)) ? mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok) : nil
|
21
82
|
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok)
|
22
83
|
end;
|
23
84
|
ENDOFMUSTBEARRAYMETHOD
|
@@ -28,8 +89,7 @@
|
|
28
89
|
Kernel.block_given? ? r.each_with_object({}) {|(k,v), h| h[k] = procBlok.call(v) } : r
|
29
90
|
end;
|
30
91
|
def mustbe_MUSTBE_NAME_key_or_nil_with_proc_or_croak(testValue, keyName, *tellTales, &procBlok)
|
31
|
-
|
32
|
-
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok)
|
92
|
+
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok)
|
33
93
|
end;
|
34
94
|
ENDOFMUSTBEHASHMETHOD
|
35
95
|
|
@@ -40,9 +100,9 @@
|
|
40
100
|
ENDOFMUSTBERESULTMETHOD
|
41
101
|
|
42
102
|
mustbeMethodCollectionsText = <<-'ENDOFHERE'
|
43
|
-
def
|
103
|
+
def mustbe_MUSTBE_NAME_list_or_croak(testValues, &procBlock) # collections
|
44
104
|
haveBlock = Kernel.block_given? && procBlock
|
45
|
-
|
105
|
+
testValues.map {|v| mustbe_MUSTBE_NAME_or_croak((haveBlock ? haveBlock.call(v) : v), 'mustbe_MUSTBE_NAME') }
|
46
106
|
end;
|
47
107
|
ENDOFHERE
|
48
108
|
|
@@ -68,38 +128,31 @@
|
|
68
128
|
|
69
129
|
isvalueMethodText = <<-'ENDOFISVALUEMETHOD'
|
70
130
|
def is_value_MUSTBE_NAME?(testValue)
|
71
|
-
IS_VALUE_TEST ? testValue : nil
|
72
|
-
|
131
|
+
r = IS_VALUE_TEST ? testValue : nil
|
132
|
+
end;
|
73
133
|
ENDOFISVALUEMETHOD
|
74
134
|
|
75
135
|
isvaluecollectionwithkeysMethodText = <<-'ENDOFHERE'
|
76
136
|
def is_value_MUSTBE_NAME?(testValue)
|
77
|
-
|
78
|
-
#(testValue.is_a?(Hash) && is_value_subset?(testValue.keys, KEY_NAMES)) ? testValue : nil
|
79
|
-
testValue.is_a?(Hash) && is_value_subset?(testValue.keys, KEY_NAMES) && testValue
|
137
|
+
testValue.is_a?(Hash) && is_value_subset?(testValue.keys, KEY_NAMES) && testValue
|
80
138
|
end;
|
81
139
|
ENDOFHERE
|
82
140
|
|
83
141
|
isvaluetypedarrayMethodText = <<-'ENDOFHERE'
|
84
142
|
def is_value_MUSTBE_NAME?(testValue)
|
85
|
-
|
86
|
-
#(testValue.is_a?(Array) && (testValue.all? {|v| v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT })) ? testValue : nil
|
87
|
-
testValue.is_a?(Array) && (testValue.all? {|v| v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT }) && testValue
|
143
|
+
testValue.is_a?(Array) && (testValue.all? {|v| v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT }) && testValue
|
88
144
|
end;
|
89
145
|
ENDOFHERE
|
90
146
|
|
91
|
-
|
147
|
+
isvaluetypedcollectionMethodText = <<-'ENDOFHERE'
|
92
148
|
def is_value_MUSTBE_NAME?(testValue)
|
93
|
-
|
94
|
-
#(testValue.is_a?(Hash) && (testValue.all? {|k,v| is_value_KEY_TYPE?(k) && (v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT) })) ? testValue : nil
|
95
|
-
testValue.is_a?(Hash) && (testValue.all? {|k,v| is_value_KEY_TYPE?(k) && (v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT) }) && testValue
|
149
|
+
testValue.is_a?(Hash) && (testValue.all? {|k,v| IS_COLLECTION_KEY_TEST && (v ? IS_COLLECTION_VALUE_TEST : VALUE_IS_NIL_RESULT) }) && testValue
|
96
150
|
end;
|
97
151
|
ENDOFHERE
|
98
|
-
|
152
|
+
|
99
153
|
isvaluetypedcollectionwithkeysMethodText = <<-'ENDOFHERE'
|
100
154
|
def is_value_MUSTBE_NAME?(testValue)
|
101
|
-
|
102
|
-
(testValue.is_a?(Hash) && is_value_subset?(testValue.keys, KEY_NAMES) && (testValue.all? {|k,v| is_value_KEY_TYPE?(k) && (v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT) })) ? testValue : nil
|
155
|
+
(testValue.is_a?(Hash) && is_value_subset?(testValue.keys, KEY_NAMES) && (testValue.all? {|k,v| is_value_KEY_TYPE?(k) && (v ? is_value_VALUE_TYPE?(v) : VALUE_IS_NIL_RESULT) })) ? testValue : nil
|
103
156
|
end;
|
104
157
|
ENDOFHERE
|
105
158
|
|
@@ -109,7 +162,6 @@
|
|
109
162
|
|
110
163
|
isvaluevalueisAliasText = '' # TURN OFF ALIAS - TOO DNAGEROUS IF IS_VALUE OVERRIDDEN
|
111
164
|
|
112
|
-
|
113
165
|
mustbeMethodKeyText = <<-'ENDOFMUSTBEKEYMETHOD'
|
114
166
|
def mustbe_MUSTBE_NAME_key_or_croak(testValue, keyName, *tellTales)
|
115
167
|
mustbe_MUSTBE_NAME_or_croak(mustbe_key_or_croak(testValue, keyName, *tellTales), *tellTales)
|
@@ -119,13 +171,39 @@
|
|
119
171
|
end;
|
120
172
|
ENDOFMUSTBEKEYMETHOD
|
121
173
|
|
174
|
+
findMethodKeyText = <<-'ENDOFHERE'
|
175
|
+
def find_MUSTBE_NAME_key_or_croak(testValue, *tellTales)
|
176
|
+
mustbe_MUSTBE_NAME_or_croak(mustbe_key_or_croak(testValue, :MUSTBE_KEY_NAME, *tellTales), *tellTales)
|
177
|
+
end;
|
178
|
+
def find_MUSTBE_NAME_key_or_nil_or_croak(testValue, *tellTales)
|
179
|
+
mustbe_MUSTBE_NAME_key_or_nil_or_croak(testValue, :MUSTBE_KEY_NAME, *tellTales)
|
180
|
+
end;
|
181
|
+
ENDOFHERE
|
182
|
+
|
183
|
+
setMethodKeyText = <<-'ENDOFHERE'
|
184
|
+
def set_MUSTBE_NAME_key_or_croak(setHash, setValue, *tellTales)
|
185
|
+
mustbe_hash_or_croak(setHash)[:MUSTBE_KEY_NAME] = mustbe_MUSTBE_NAME_or_croak(setValue, *tellTales)
|
186
|
+
setHash
|
187
|
+
end;
|
188
|
+
ENDOFHERE
|
189
|
+
|
190
|
+
getMethodKeyNameText = <<-'ENDOFHERE'
|
191
|
+
def get_MUSTBE_NAME_key_name
|
192
|
+
:MUSTBE_KEY_NAME
|
193
|
+
end;
|
194
|
+
ENDOFHERE
|
195
|
+
|
196
|
+
mergeMethodKeyText = <<-'ENDOFHERE'
|
197
|
+
def merge_MUSTBE_NAME_key_or_croak(mergeHash, mergeValue, *tellTales)
|
198
|
+
mustbe_hash_or_croak(mergeHash).merge(:MUSTBE_KEY_NAME => mustbe_MUSTBE_NAME_or_croak(mergeValue, *tellTales))
|
199
|
+
end;
|
200
|
+
ENDOFHERE
|
201
|
+
|
122
202
|
mustbeMethodSubsetText = <<-'ENDOFMUSTBESUBSETMETHOD'
|
123
203
|
def mustbe_subset_or_croak(subSet, superSet, *tellTales)
|
124
|
-
###mustbe_empty_or_croak(mustbe_array_or_croak(subSet, :mustbe_subset1, *tellTales) - mustbe_array_or_croak(superSet, :mustbe_subset2, *tellTales), :mustbe_subset, *tellTales)
|
125
204
|
(r = is_value_subset?(subSet, superSet)) ? r : contract_exception(subSet, "value failed is_value_subset? test on superSet >#{superSet}<", *tellTales)
|
126
205
|
end;
|
127
206
|
def is_value_subset?(subSet, superSet)
|
128
|
-
#(subSet.is_a?(Array) && superSet.is_a?(Array) && (subSet - superSet).empty?) ? subSet : nil
|
129
207
|
subSet.is_a?(Array) && superSet.is_a?(Array) && (subSet - superSet).empty? && subSet
|
130
208
|
end
|
131
209
|
ENDOFMUSTBESUBSETMETHOD
|
@@ -139,39 +217,39 @@
|
|
139
217
|
|
140
218
|
mustbeMethodCompareText = <<-'ENDOFMETHOD'
|
141
219
|
def mustbe_MUSTBE_NAME_or_croak(arg1, arg2, *args)
|
142
|
-
#eye = :MUSTBE_NAME
|
143
220
|
arg1.is_a?(arg2.class) || contract_exception(arg1, :MUSTBE_NAME, "DIFFERNT CLASSES arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<", *args)
|
144
221
|
argC = (arg1 MUSTBE_SPEC arg2)
|
145
|
-
# puts "<=> #{eye} argC >#{argC.class}< >#{argC}< arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<"
|
146
222
|
argC ? arg1 : contract_exception(argC, "argC >#{argC.class}< >#{argC}< arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<", *args)
|
147
223
|
end;
|
148
224
|
ENDOFMETHOD
|
149
225
|
|
150
|
-
|
151
|
-
|
226
|
+
# accessors
|
227
|
+
|
228
|
+
snippetBaseAccessor = <<-'ENDOFHERE'
|
152
229
|
def ACCESSOR_NAME
|
153
|
-
@ACCESSOR_NAME ||=
|
230
|
+
@ACCESSOR_NAME ||= ACCESSOR_DEFAULT
|
154
231
|
end;
|
155
|
-
def
|
232
|
+
def reset_ACCESSOR_NAME
|
233
|
+
@ACCESSOR_NAME = nil
|
234
|
+
end;
|
235
|
+
alias_method :'get_ACCESSOR_NAME', :'ACCESSOR_NAME'
|
236
|
+
ENDOFHERE
|
237
|
+
|
238
|
+
snippetAccessor = <<-'ENDOFHERE'
|
239
|
+
def ACCESSOR_NAME=(value)
|
156
240
|
@ACCESSOR_NAME = value
|
157
241
|
end;
|
242
|
+
alias_method :'set_ACCESSOR_NAME', :'ACCESSOR_NAME='
|
158
243
|
ENDOFHERE
|
159
244
|
|
160
245
|
snippetAccessorWithContractText = <<-'ENDOFHERE'
|
161
|
-
def ACCESSOR_NAME
|
162
|
-
@ACCESSOR_NAME ||= nil
|
163
|
-
end;
|
164
|
-
def reset_ACCESSOR_NAME
|
165
|
-
@ACCESSOR_NAME = nil
|
166
|
-
end;
|
167
|
-
def find_ACCESSOR_NAME_or_croak
|
168
|
-
mustbe_ACCESSOR_CONTRACT_or_croak(ACCESSOR_NAME, :f_ACCESSOR_NAME, "value not ACCESSOR_CONTRACT")
|
169
|
-
end;
|
170
246
|
def ACCESSOR_NAME=(value)
|
171
247
|
@ACCESSOR_NAME = mustbe_ACCESSOR_CONTRACT_or_croak(value, :s_ACCESSOR_NAME, "value not ACCESSOR_CONTRACT")
|
172
248
|
end;
|
173
249
|
alias_method :'set_ACCESSOR_NAME', :'ACCESSOR_NAME='
|
174
|
-
|
250
|
+
def find_ACCESSOR_NAME_or_croak
|
251
|
+
mustbe_ACCESSOR_CONTRACT_or_croak(ACCESSOR_NAME, :f_ACCESSOR_NAME, "value not ACCESSOR_CONTRACT")
|
252
|
+
end;
|
175
253
|
ENDOFHERE
|
176
254
|
|
177
255
|
accessorEdits = {
|
@@ -182,30 +260,39 @@
|
|
182
260
|
|
183
261
|
valueisnilresultEdits = {VALUE_IS_NIL_RESULT: 'false'} # default for typed collections is not ok if nil
|
184
262
|
|
185
|
-
packageMustbeText = [mustbeMethodOneArgText, mustbeMethodKeyText, mustbeCommonText, isvalueMethodText, isvaluevalueisAliasText].flatten.join
|
263
|
+
packageMustbeText = [mustbeMethodOneArgText, mustbeMethodKeyText, findMethodKeyText, setMethodKeyText, getMethodKeyNameText, mergeMethodKeyText, mustbeCommonText, isvalueMethodText, isvaluevalueisAliasText].flatten.join
|
186
264
|
|
187
|
-
packageAccessorSpec = [snippetAccessor].flatten
|
265
|
+
packageAccessorSpec = [snippetBaseAccessor, snippetAccessor].flatten
|
188
266
|
|
189
267
|
packageAccessorWithContractBaseSpec = [mustbeMethodOneArgText, mustbeMethodKeyText, mustbeMethodOneArgOrNilText, isvaluevalueisAliasText].flatten
|
190
268
|
packageAccessorWithContractSpec = [isvalueMethodText, packageAccessorWithContractBaseSpec].flatten
|
191
269
|
packageAccessorWithContractNoIsValueSpec = packageAccessorWithContractBaseSpec
|
192
270
|
|
193
271
|
packageAccessorText = Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, packageAccessorSpec)
|
194
|
-
packageAccessorWithContractText = Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, snippetAccessorWithContractText, packageAccessorWithContractSpec)
|
195
|
-
packageAccessorWithContractNoIsValueText = Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, snippetAccessorWithContractText, packageAccessorWithContractNoIsValueSpec)
|
272
|
+
packageAccessorWithContractText = Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, snippetBaseAccessor, snippetAccessorWithContractText, packageAccessorWithContractSpec)
|
273
|
+
packageAccessorWithContractNoIsValueText = Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, snippetBaseAccessor, snippetAccessorWithContractText, packageAccessorWithContractNoIsValueSpec)
|
196
274
|
|
275
|
+
packageAccessorEdit = {
|
276
|
+
'ACCESSOR_DEFAULT' => 'nil',
|
277
|
+
}
|
278
|
+
|
197
279
|
dynamicMethodTexts = {
|
198
280
|
|
199
281
|
# accessors
|
200
282
|
|
201
|
-
package_accessor: packageAccessorText,
|
202
|
-
package_accessor_with_contract: packageAccessorWithContractText,
|
203
|
-
package_accessor_with_contract_no_is_value: packageAccessorWithContractNoIsValueText,
|
283
|
+
package_accessor: {edit: packageAccessorEdit, spec: packageAccessorText},
|
284
|
+
package_accessor_with_contract: {edit: packageAccessorEdit, spec: packageAccessorWithContractText},
|
285
|
+
package_accessor_with_contract_no_is_value: {edit: packageAccessorEdit, spec: packageAccessorWithContractNoIsValueText},
|
204
286
|
|
205
287
|
method_accessor_is_value_collection_with_keys: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluecollectionwithkeysMethodText)},
|
206
288
|
method_accessor_is_value_typed_collection: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionMethodText)},
|
207
289
|
method_accessor_is_value_typed_collection_with_keys: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionwithkeysMethodText)},
|
208
290
|
|
291
|
+
method_accessor_is_value_typed_hash: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionMethodText)},
|
292
|
+
method_accessor_is_value_typed_hash_with_keys: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionwithkeysMethodText)},
|
293
|
+
|
294
|
+
method_accessor_is_value_typed_array: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedarrayMethodText, mustbeArrayWithProcText)},
|
295
|
+
|
209
296
|
# contracts
|
210
297
|
|
211
298
|
package_mustbe: packageMustbeText,
|
@@ -224,6 +311,8 @@
|
|
224
311
|
method_mustbe_is_value_typed_array: {edit: valueisnilresultEdits, spec: [isvaluetypedarrayMethodText, mustbeArrayWithProcText]},
|
225
312
|
|
226
313
|
method_mustbe_is_value_typed_collection_with_keys: {edit: valueisnilresultEdits, spec: isvaluetypedcollectionwithkeysMethodText},
|
314
|
+
|
315
|
+
method_mustbe_is_value_contract_collection_with_nil_values: {proc: isvaluecontractcollectionwithnilvaluesProc},
|
227
316
|
|
228
317
|
method_mustbe_hash_with_proc: mustbeHashWithProcText,
|
229
318
|
method_mustbe_array_with_proc: mustbeArrayWithProcText,
|
@@ -250,5 +339,5 @@
|
|
250
339
|
|
251
340
|
|
252
341
|
|
342
|
+
end
|
253
343
|
__END__
|
254
|
-
|
@@ -1,19 +1,19 @@
|
|
1
1
|
|
2
2
|
# potrubi text snippets
|
3
3
|
|
4
|
-
# looks up
|
4
|
+
# looks up snippets by name in dictionaries
|
5
5
|
|
6
6
|
# values normally code to be dynamically dused by e.g. Dynamic and COntract
|
7
7
|
|
8
8
|
require_relative '../bootstrap'
|
9
9
|
|
10
|
-
#requireList = %w(dynamic)
|
11
|
-
#requireList.each {|r| require_relative "#{r}"}
|
12
|
-
|
13
10
|
mixinContent = Module.new do
|
14
11
|
|
15
12
|
include Potrubi::Bootstrap
|
16
13
|
|
14
|
+
# Dictionary Methods
|
15
|
+
# ##################
|
16
|
+
|
17
17
|
def dictionary_index
|
18
18
|
@dictionary_index ||= {}
|
19
19
|
end
|
@@ -35,7 +35,14 @@ mixinContent = Module.new do
|
|
35
35
|
def is_value_dictionary_name?(dictName)
|
36
36
|
dictionary_index[normalise_dictionary_name(dictName)]
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
|
+
def find_dictionary_home_or_croak
|
40
|
+
eye = :'f_dict_home'
|
41
|
+
dictHome = File.expand_path(__FILE__ + "/../snippet-dictionaries")
|
42
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, "dictHome >#{dictHome.class}< >#{dictHome}<")
|
43
|
+
dictHome
|
44
|
+
end
|
45
|
+
|
39
46
|
def find_dictionary_or_croak(dictName, &dictBlok)
|
40
47
|
eye = :'f_dict'
|
41
48
|
eyeTale = 'FIND SNIP DICT'
|
@@ -62,8 +69,13 @@ mixinContent = Module.new do
|
|
62
69
|
|
63
70
|
end
|
64
71
|
|
72
|
+
def load_home_dictionaries_or_croak(snipDicts)
|
73
|
+
dictHome = find_dictionary_home_or_croak
|
74
|
+
snipDictsHome = potrubi_bootstrap_mustbe_hash_or_croak(snipDicts).each_with_object({}) { | (k,v), h| h[k] = File.join(dictHome, "#{v}.rb") }
|
75
|
+
load_dictionaries_or_croak(snipDictsHome)
|
76
|
+
end
|
77
|
+
|
65
78
|
def load_dictionaries_or_croak(snipDicts)
|
66
|
-
#potrubi_bootstrap_mustbe_hash_or_croak(snipDicts).each {|k,v| puts("LOAD DICT k >#{k}< v >#{v}<"); load_dictionary_or_croak(k, v) }
|
67
79
|
potrubi_bootstrap_mustbe_hash_or_croak(snipDicts).each {|k,v| load_dictionary_or_croak(k, v) }
|
68
80
|
end
|
69
81
|
|
@@ -75,8 +87,17 @@ mixinContent = Module.new do
|
|
75
87
|
|
76
88
|
### let require work it ok potrubi_bootstrap_mustbe_file_or_croak(dictPath, eye, "dictPath not a file")
|
77
89
|
|
78
|
-
|
90
|
+
dictResult = instance_eval(File.read(dictPath))
|
79
91
|
|
92
|
+
dictHash = case dictResult
|
93
|
+
when Hash then dictResult
|
94
|
+
when Proc then dictResult.call
|
95
|
+
else
|
96
|
+
potrubi_bootstrap_surprise_exception(dictResult, eye, "dictResult is what?")
|
97
|
+
end
|
98
|
+
|
99
|
+
potrubi_bootstrap_mustbe_hash_or_croak(dictHash, eye)
|
100
|
+
|
80
101
|
dictNameNrm = normalise_dictionary_name(dictName)
|
81
102
|
|
82
103
|
add_dictionaries_to_index(dictNameNrm => dictHash)
|
@@ -87,6 +108,9 @@ mixinContent = Module.new do
|
|
87
108
|
|
88
109
|
end
|
89
110
|
|
111
|
+
# Snippet Methods
|
112
|
+
# ###############
|
113
|
+
|
90
114
|
def map_snippets_or_croak(dictName, *snippetList, &snipBlok)
|
91
115
|
eye = :'map_snippets'
|
92
116
|
eyeTale = 'MAP SNIPPETS'
|
@@ -97,7 +121,7 @@ mixinContent = Module.new do
|
|
97
121
|
|
98
122
|
snippetMaps = snippetList.flatten(1).map { | snippetName | snippetHash.has_key?(snippetName) ? snippetHash[snippetName] : snippetName }
|
99
123
|
|
100
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}< snippetMaps
|
124
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}<", potrubi_bootstrap_logger_fmt_kls_size(snippetMaps: snippetMaps))
|
101
125
|
|
102
126
|
potrubi_bootstrap_mustbe_array_or_croak(snippetMaps, eye)
|
103
127
|
|
@@ -111,7 +135,7 @@ mixinContent = Module.new do
|
|
111
135
|
# if snippetName not present, calls block if given, else exception
|
112
136
|
|
113
137
|
def find_snippets_or_croak(dictName, *snippetList, &snipBlok)
|
114
|
-
eye = :
|
138
|
+
eye = :f_snips
|
115
139
|
eyeTale = 'FIND SNIPPETS'
|
116
140
|
|
117
141
|
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "dictName >#{dictName}< snippetList >#{snippetList}< snipBlok >#{snipBlok}<")
|
@@ -122,7 +146,15 @@ mixinContent = Module.new do
|
|
122
146
|
case snippetName
|
123
147
|
when Symbol then
|
124
148
|
case
|
125
|
-
when dictHash.has_key?(snippetName) then
|
149
|
+
when dictHash.has_key?(snippetName) then
|
150
|
+
snippetValueNom = dictHash[snippetName]
|
151
|
+
snippetValueNrm = case snippetValueNom
|
152
|
+
when Proc then
|
153
|
+
dictHash[snippetName] = snippetValueNom.call # update dict
|
154
|
+
else
|
155
|
+
snippetValueNom
|
156
|
+
end
|
157
|
+
h[snippetName] = snippetValueNrm
|
126
158
|
else
|
127
159
|
h[snippetName] = Kernel.block_given? ? snipBlok.call(dictHash, snippetName) : potrubi_bootstrap_mustbe_not_nil_or_croak(dictHash[snippetName], eye, "snippetName >#{snippetName}< not found")
|
128
160
|
end
|
@@ -131,52 +163,32 @@ mixinContent = Module.new do
|
|
131
163
|
end
|
132
164
|
end
|
133
165
|
|
134
|
-
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}< snippetMaps >#{snippetMaps}<")
|
166
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}< snippetMaps >#{snippetMaps.size}<")
|
135
167
|
|
136
168
|
potrubi_bootstrap_mustbe_hash_or_croak(snippetMaps, eye)
|
137
169
|
|
138
170
|
end
|
171
|
+
|
172
|
+
|
139
173
|
end
|
174
|
+
|
140
175
|
module Potrubi
|
141
176
|
module Mixin
|
142
|
-
module
|
177
|
+
module SnippetManager
|
143
178
|
end
|
144
179
|
end
|
145
180
|
end
|
146
181
|
|
147
|
-
##Potrubi::Mixin::
|
148
|
-
Potrubi::Mixin::
|
182
|
+
##Potrubi::Mixin::SnippetManager.__send__(:include, mixinContent) # Instance Methods
|
183
|
+
Potrubi::Mixin::SnippetManager.extend(mixinContent) # Module Methods
|
149
184
|
|
150
185
|
# load some dictionaries
|
151
186
|
|
152
187
|
#$DEBUG = true
|
153
188
|
#$DEBUG_POTRUBI_BOOTSTRAP = true
|
154
189
|
|
155
|
-
snipDicts = {dynamic_methods: File.expand_path(__FILE__ + "/../text-snippets/methods-text-snippets.rb")}
|
156
|
-
Potrubi::Mixin::TextSnippets.load_dictionaries_or_croak(snipDicts)
|
157
|
-
|
158
|
-
#STOPHERELOADSNIPDICTS
|
159
|
-
|
160
|
-
__END__
|
161
|
-
|
162
|
-
# quick test
|
163
|
-
|
164
|
-
|
165
|
-
$DEBUG = true
|
166
|
-
$DEBUG_POTRUBI_BOOTSTRAP = true
|
167
|
-
|
168
|
-
Potrubi::Mixin::TextSnippets.find_dictionary_or_croak(:dynamic_methods)
|
169
|
-
|
170
|
-
#Potrubi::Mixin::TextSnippets.load_dictionary_or_croak('.x/y') # fail
|
171
|
-
|
172
|
-
snipLook = Potrubi::Mixin::TextSnippets.find_snippets_or_croak(:dynamic_methods, :package_mustbe)
|
173
|
-
|
174
|
-
puts("snipLook >#{snipLook.class}< >#{snipLook}<")
|
175
|
-
|
176
|
-
snipLook = Potrubi::Mixin::TextSnippets.find_snippets_or_croak(:dynamic_methods, :package_mustbe) { |d,s| s } # will work
|
177
|
-
|
178
|
-
snipLook = Potrubi::Mixin::TextSnippets.find_snippets_or_croak(:dynamic_methods, :xxxxxxpackage_mustbe) # will fail
|
179
190
|
|
191
|
+
snipDicts = {dynamic_methods: :'methods-text-snippets'}
|
192
|
+
Potrubi::Mixin::SnippetManager.load_home_dictionaries_or_croak(snipDicts)
|
180
193
|
|
181
194
|
__END__
|
182
|
-
|