potrubi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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,59 @@
|
|
1
|
+
|
2
|
+
# potrubi methods for top level scripts
|
3
|
+
|
4
|
+
require_relative '../core'
|
5
|
+
|
6
|
+
#requireList = %w(bootstrap)
|
7
|
+
#requireList.each {|r| require_relative "#{r}"}
|
8
|
+
|
9
|
+
mixinContent = Module.new do
|
10
|
+
|
11
|
+
include Potrubi::Bootstrap
|
12
|
+
|
13
|
+
# Script Methods
|
14
|
+
# ##############
|
15
|
+
|
16
|
+
#=begin
|
17
|
+
def find_script_name_or_croak(scriptPath=$0)
|
18
|
+
File.basename(scriptPath, ".*")
|
19
|
+
end
|
20
|
+
def find_script_directory_or_croak(scriptPath=$0)
|
21
|
+
potrubi_bootstrap_mustbe_directory_or_croak(File.dirname(scriptPath))
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_script_home_directory_or_croak(scriptPath=$0)
|
25
|
+
potrubi_bootstrap_mustbe_directory_or_croak(File.expand_path(File.join(find_script_directory_or_croak(scriptPath), '/../')))
|
26
|
+
end
|
27
|
+
alias_method :find_script_home_or_croak, :find_script_home_directory_or_croak
|
28
|
+
|
29
|
+
def find_script_lib_directory_or_croak(scriptPath=$0)
|
30
|
+
potrubi_bootstrap_mustbe_directory_or_croak(File.join(find_script_home_directory_or_croak(scriptPath), 'lib'))
|
31
|
+
end
|
32
|
+
alias_method :find_script_lib_or_croak, :find_script_lib_directory_or_croak
|
33
|
+
|
34
|
+
def find_script_peer_directory_or_croak(peerName, scriptPath=$0)
|
35
|
+
potrubi_bootstrap_mustbe_directory_or_croak(File.expand_path(File.join(find_script_home_directory_or_croak(scriptPath), peerName, find_script_name_or_croak(scriptPath))))
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_script_data_directory_or_croak(dirName='data', scriptPath=$0)
|
39
|
+
find_script_peer_directory_or_croak(dirName, scriptPath)
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_script_results_directory_or_croak(dirName='results', scriptPath=$0)
|
43
|
+
find_script_peer_directory_or_croak(dirName, scriptPath)
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_script_config_directory_or_croak(dirName='config', scriptPath=$0)
|
47
|
+
find_script_peer_directory_or_croak(dirName, scriptPath)
|
48
|
+
end
|
49
|
+
#=end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
mixinConstant = Potrubi::Core.assign_mixin_constant_or_croak(mixinContent, __FILE__)
|
54
|
+
|
55
|
+
mixinConstant.extend(mixinContent) # Class Methods - more likely use case
|
56
|
+
|
57
|
+
__END__
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
# potrubi text snippets
|
3
|
+
|
4
|
+
# looks up sniipets by name in dictionaries
|
5
|
+
|
6
|
+
# values normally code to be dynamically dused by e.g. Dynamic and COntract
|
7
|
+
|
8
|
+
require_relative '../bootstrap'
|
9
|
+
|
10
|
+
requireList = %w(dynamic)
|
11
|
+
requireList.each {|r| require_relative "#{r}"}
|
12
|
+
|
13
|
+
mixinContent = Module.new do
|
14
|
+
|
15
|
+
include Potrubi::Bootstrap
|
16
|
+
|
17
|
+
def dictionary_index
|
18
|
+
@dictionary_index ||= {}
|
19
|
+
end
|
20
|
+
def dictionary_index=(dictNew)
|
21
|
+
@dictionary_index = potrubi_bootstrap_mustbe_hash_or_croak(dictNew)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_dictionaries_to_index(snipDicts)
|
25
|
+
potrubi_bootstrap_mustbe_hash_or_croak(snipDicts)
|
26
|
+
snipIndex = dictionary_index
|
27
|
+
newsnipIndex = snipIndex.merge(snipDicts.each_with_object({}) {|(k,v),h| h[normalise_dictionary_name(k)] = potrubi_bootstrap_mustbe_hash_or_croak(v) })
|
28
|
+
self.dictionary_index = newsnipIndex
|
29
|
+
end
|
30
|
+
|
31
|
+
def normalise_dictionary_name(dictName)
|
32
|
+
dictName.to_s.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_value_dictionary_name?(dictName)
|
36
|
+
dictionary_index[normalise_dictionary_name(dictName)]
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_dictionary_or_croak(dictName, &dictBlok)
|
40
|
+
eye = :'f_dict'
|
41
|
+
eyeTale = 'FIND SNIP DICT'
|
42
|
+
|
43
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "dictName >#{dictName.class}< >#{dictName.class}< dictBlok >#{dictBlok}<")
|
44
|
+
|
45
|
+
dictHash = case dictName
|
46
|
+
when Hash then dictName
|
47
|
+
when String, Symbol then
|
48
|
+
case
|
49
|
+
when (r = is_value_dictionary_name?(dictName)) then r
|
50
|
+
else
|
51
|
+
potrubi_bootstrap_surprise_exception(dictName, "dictName is not a dictionary")
|
52
|
+
end
|
53
|
+
else
|
54
|
+
potrubi_bootstrap_surprise_exception(dictName, "dictName is what?")
|
55
|
+
end
|
56
|
+
|
57
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName.class}< >#{dictName}< dictHash >#{dictHash.size}<")
|
58
|
+
|
59
|
+
# dictionaries must be hashes
|
60
|
+
|
61
|
+
potrubi_bootstrap_mustbe_hash_or_croak(dictHash, eye, "dictName >#{dictName}< not a hash")
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
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
|
+
potrubi_bootstrap_mustbe_hash_or_croak(snipDicts).each {|k,v| load_dictionary_or_croak(k, v) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_dictionary_or_croak(dictName, dictPath, &dictBlok)
|
71
|
+
eye = :'l_dict'
|
72
|
+
eyeTale = 'LOAD DICT FILE'
|
73
|
+
|
74
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "dictName >#{dictName.class}< >#{dictName}< dictPath >#{dictPath.class}< >#{dictPath}< dictBlok >#{dictBlok}<")
|
75
|
+
|
76
|
+
### let require work it ok potrubi_bootstrap_mustbe_file_or_croak(dictPath, eye, "dictPath not a file")
|
77
|
+
|
78
|
+
dictHash = potrubi_bootstrap_mustbe_hash_or_croak(instance_eval(File.open(dictPath).readlines.join("\n")))
|
79
|
+
|
80
|
+
dictNameNrm = normalise_dictionary_name(dictName)
|
81
|
+
|
82
|
+
add_dictionaries_to_index(dictNameNrm => dictHash)
|
83
|
+
|
84
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictNameNrm.class}< >#{dictNameNrm}< dictHash >#{dictHash.size}< >#{dictHash}<")
|
85
|
+
|
86
|
+
dictHash
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def map_snippets_or_croak(dictName, *snippetList, &snipBlok)
|
91
|
+
eye = :'map_snippets'
|
92
|
+
eyeTale = 'MAP SNIPPETS'
|
93
|
+
|
94
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "dictName >#{dictName}< snippetList >#{snippetList}< snipBlok >#{snipBlok}<")
|
95
|
+
|
96
|
+
snippetHash = find_snippets_or_croak(dictName, *snippetList)
|
97
|
+
|
98
|
+
snippetMaps = snippetList.flatten(1).map { | snippetName | snippetHash.has_key?(snippetName) ? snippetHash[snippetName] : snippetName }
|
99
|
+
|
100
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}< snippetMaps >#{snippetMaps}<")
|
101
|
+
|
102
|
+
potrubi_bootstrap_mustbe_array_or_croak(snippetMaps, eye)
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
# looks up a array of possible snippets
|
107
|
+
# retruns a hash of snippetName, snippetValue pairs
|
108
|
+
|
109
|
+
# if snippetName not Symbol, ignores
|
110
|
+
|
111
|
+
# if snippetName not present, calls block if given, else exception
|
112
|
+
|
113
|
+
def find_snippets_or_croak(dictName, *snippetList, &snipBlok)
|
114
|
+
eye = :'f_snippets'
|
115
|
+
eyeTale = 'FIND SNIPPETS'
|
116
|
+
|
117
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, "dictName >#{dictName}< snippetList >#{snippetList}< snipBlok >#{snipBlok}<")
|
118
|
+
|
119
|
+
dictHash = find_dictionary_or_croak(dictName)
|
120
|
+
|
121
|
+
snippetMaps = snippetList.flatten(1).uniq.each_with_object({}) do | snippetName, h |
|
122
|
+
case snippetName
|
123
|
+
when Symbol then
|
124
|
+
case
|
125
|
+
when dictHash.has_key?(snippetName) then h[snippetName] = dictHash[snippetName]
|
126
|
+
else
|
127
|
+
h[snippetName] = Kernel.block_given? ? snipBlok.call(dictHash, snippetName) : potrubi_bootstrap_mustbe_not_nil_or_croak(dictHash[snippetName], eye, "snippetName >#{snippetName}< not found")
|
128
|
+
end
|
129
|
+
else
|
130
|
+
###snippetName # ignore
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, "dictName >#{dictName}< snippetMaps >#{snippetMaps}<")
|
135
|
+
|
136
|
+
potrubi_bootstrap_mustbe_hash_or_croak(snippetMaps, eye)
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
140
|
+
module Potrubi
|
141
|
+
module Mixin
|
142
|
+
module TextSnippets
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
##Potrubi::Mixin::TextSnippets.__send__(:include, mixinContent) # Instance Methods
|
148
|
+
Potrubi::Mixin::TextSnippets.extend(mixinContent) # Module Methods
|
149
|
+
|
150
|
+
# load some dictionaries
|
151
|
+
|
152
|
+
#$DEBUG = true
|
153
|
+
#$DEBUG_POTRUBI_BOOTSTRAP = true
|
154
|
+
|
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
|
+
|
180
|
+
|
181
|
+
__END__
|
182
|
+
|
@@ -0,0 +1,254 @@
|
|
1
|
+
|
2
|
+
# potrubi text snippets
|
3
|
+
|
4
|
+
# methods dictionary
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
mustbeMethodOneArgText = <<-'ENDOFMUSTBESCALARMETHOD'
|
9
|
+
def mustbe_MUSTBE_NAME_or_croak(testValue, *tellTales)
|
10
|
+
is_value_MUSTBE_NAME?(testValue) ? testValue : contract_exception(testValue, "value failed is_value_MUSTBE_NAME?", *tellTales)
|
11
|
+
end;
|
12
|
+
ENDOFMUSTBESCALARMETHOD
|
13
|
+
|
14
|
+
mustbeArrayWithProcText = <<-'ENDOFMUSTBEARRAYMETHOD'
|
15
|
+
def mustbe_MUSTBE_NAME_with_proc_or_croak(testValue, *tellTales, &procBlok)
|
16
|
+
r = mustbe_MUSTBE_NAME_or_croak(testValue, *tellTales)
|
17
|
+
Kernel.block_given? ? r.map {|v| procBlok.call(v) } : r
|
18
|
+
end;
|
19
|
+
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
|
+
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok)
|
22
|
+
end;
|
23
|
+
ENDOFMUSTBEARRAYMETHOD
|
24
|
+
|
25
|
+
mustbeHashWithProcText = <<-'ENDOFMUSTBEHASHMETHOD'
|
26
|
+
def mustbe_MUSTBE_NAME_with_proc_or_croak(testValue, *tellTales, &procBlok)
|
27
|
+
r = mustbe_MUSTBE_NAME_or_croak(testValue, *tellTales, &procBlok)
|
28
|
+
Kernel.block_given? ? r.each_with_object({}) {|(k,v), h| h[k] = procBlok.call(v) } : r
|
29
|
+
end;
|
30
|
+
def mustbe_MUSTBE_NAME_key_or_nil_with_proc_or_croak(testValue, keyName, *tellTales, &procBlok)
|
31
|
+
#(r = is_value_key?(testValue, keyName)) ? mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok) : nil
|
32
|
+
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_with_proc_or_croak(r, *tellTales, &procBlok)
|
33
|
+
end;
|
34
|
+
ENDOFMUSTBEHASHMETHOD
|
35
|
+
|
36
|
+
mustbeMethodResultText = <<-'ENDOFMUSTBERESULTMETHOD'
|
37
|
+
def mustbe_MUSTBE_NAME_or_croak(testValue, *tellTales)
|
38
|
+
(r = is_value_MUSTBE_NAME?(testValue)) ? r : contract_exception(testValue, "value failed is_value_MUSTBE_NAME? test", *tellTales)
|
39
|
+
end;
|
40
|
+
ENDOFMUSTBERESULTMETHOD
|
41
|
+
|
42
|
+
mustbeMethodCollectionsText = <<-'ENDOFHERE'
|
43
|
+
def mustbe_MUSTBE_NAMEs_or_croak(*testValues, &procBlock) # collections
|
44
|
+
haveBlock = Kernel.block_given? && procBlock
|
45
|
+
testValues.map {|v| r = mustbe_MUSTBE_NAME_or_croak(v, 'mustbe_MUSTBE_NAME_or_croak failed'); haveBlock ? haveBlock.call(r) : r}
|
46
|
+
end;
|
47
|
+
ENDOFHERE
|
48
|
+
|
49
|
+
mustbeMethodOneArgOrNilText = <<-'ENDOFHERE'
|
50
|
+
def mustbe_MUSTBE_NAME_or_nil_or_croak(argOne, *tellTales) # or nil method
|
51
|
+
argOne && mustbe_MUSTBE_NAME_or_croak(argOne, *tellTales)
|
52
|
+
end;
|
53
|
+
ENDOFHERE
|
54
|
+
|
55
|
+
mustbeMethodTwoArgOrNilText = <<-'ENDOFHERE'
|
56
|
+
def mustbe_MUSTBE_NAME_or_nil_or_croak(argOne, argTwo, *tellTales) # or nil method
|
57
|
+
argOne && mustbe_MUSTBE_NAME_or_croak(argOne, argTwo, *tellTales)
|
58
|
+
end;
|
59
|
+
ENDOFHERE
|
60
|
+
|
61
|
+
mustbeCommonText = [mustbeMethodOneArgOrNilText, mustbeMethodCollectionsText].join
|
62
|
+
|
63
|
+
mustbeMethodOneArgOrNilWithProcText = <<-'ENDOFHERE'
|
64
|
+
def mustbe_MUSTBE_NAME_or_nil_with_proc_or_croak(argOne, *tellTales, &procBlok) # or nil method
|
65
|
+
argOne && mustbe_MUSTBE_NAME_with_proc_or_croak(argOne, *tellTales, &procBlok)
|
66
|
+
end;
|
67
|
+
ENDOFHERE
|
68
|
+
|
69
|
+
isvalueMethodText = <<-'ENDOFISVALUEMETHOD'
|
70
|
+
def is_value_MUSTBE_NAME?(testValue)
|
71
|
+
IS_VALUE_TEST ? testValue : nil
|
72
|
+
end;
|
73
|
+
ENDOFISVALUEMETHOD
|
74
|
+
|
75
|
+
isvaluecollectionwithkeysMethodText = <<-'ENDOFHERE'
|
76
|
+
def is_value_MUSTBE_NAME?(testValue)
|
77
|
+
#puts("\nCOLLECTION WITH KEYS MUSTBE_NAME KEY_NAMES >#{KEY_NAMES}< testValue >#{testValue}< >#{testValue}<")
|
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
|
80
|
+
end;
|
81
|
+
ENDOFHERE
|
82
|
+
|
83
|
+
isvaluetypedarrayMethodText = <<-'ENDOFHERE'
|
84
|
+
def is_value_MUSTBE_NAME?(testValue)
|
85
|
+
#puts("\nTYPED ARRAY MUSTBE_NAME VALUE_TYPE testValue >#{testValue}< >#{testValue}<")
|
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
|
88
|
+
end;
|
89
|
+
ENDOFHERE
|
90
|
+
|
91
|
+
isvaluetypedcollectionMethodText = <<-'ENDOFHERE'
|
92
|
+
def is_value_MUSTBE_NAME?(testValue)
|
93
|
+
#puts("TYPED COLLECTION MUSTBE_NAME KEY_TYPE VALUE_TYPE testValue >#{testValue}< >#{testValue}<")
|
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
|
96
|
+
end;
|
97
|
+
ENDOFHERE
|
98
|
+
|
99
|
+
isvaluetypedcollectionwithkeysMethodText = <<-'ENDOFHERE'
|
100
|
+
def is_value_MUSTBE_NAME?(testValue)
|
101
|
+
#puts("\nTYPED COLLECTION WITH KEYS MUSTBE_NAME KEY_TYPE VALUE_TYPE KEY_NAMES >#{KEY_NAMES}< testValue >#{testValue}< >#{testValue}<")
|
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
|
103
|
+
end;
|
104
|
+
ENDOFHERE
|
105
|
+
|
106
|
+
isvaluevalueisAliasText = <<-'ENDOFISVALUEALIAS'
|
107
|
+
alias_method :'value_is_MUSTBE_NAME?', :'is_value_MUSTBE_NAME?'
|
108
|
+
ENDOFISVALUEALIAS
|
109
|
+
|
110
|
+
isvaluevalueisAliasText = '' # TURN OFF ALIAS - TOO DNAGEROUS IF IS_VALUE OVERRIDDEN
|
111
|
+
|
112
|
+
|
113
|
+
mustbeMethodKeyText = <<-'ENDOFMUSTBEKEYMETHOD'
|
114
|
+
def mustbe_MUSTBE_NAME_key_or_croak(testValue, keyName, *tellTales)
|
115
|
+
mustbe_MUSTBE_NAME_or_croak(mustbe_key_or_croak(testValue, keyName, *tellTales), *tellTales)
|
116
|
+
end;
|
117
|
+
def mustbe_MUSTBE_NAME_key_or_nil_or_croak(testValue, keyName, *tellTales)
|
118
|
+
(r = is_value_key?(testValue, keyName)) && mustbe_MUSTBE_NAME_or_nil_or_croak(r, *tellTales)
|
119
|
+
end;
|
120
|
+
ENDOFMUSTBEKEYMETHOD
|
121
|
+
|
122
|
+
mustbeMethodSubsetText = <<-'ENDOFMUSTBESUBSETMETHOD'
|
123
|
+
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
|
+
(r = is_value_subset?(subSet, superSet)) ? r : contract_exception(subSet, "value failed is_value_subset? test on superSet >#{superSet}<", *tellTales)
|
126
|
+
end;
|
127
|
+
def is_value_subset?(subSet, superSet)
|
128
|
+
#(subSet.is_a?(Array) && superSet.is_a?(Array) && (subSet - superSet).empty?) ? subSet : nil
|
129
|
+
subSet.is_a?(Array) && superSet.is_a?(Array) && (subSet - superSet).empty? && subSet
|
130
|
+
end
|
131
|
+
ENDOFMUSTBESUBSETMETHOD
|
132
|
+
|
133
|
+
mustbeMethodTwoArgText = <<-'ENDOFMUSTBEMETHODS'
|
134
|
+
def mustbe_MUSTBE_NAME_or_croak(argOne, argTwo, *tellTales)
|
135
|
+
(r = is_value_MUSTBE_NAME?(argOne, argTwo)) ? r : contract_exception(argTwo, "argOne >#{argOne.class}< argTwo failed is_value_MUSTBE_NAME?", *tellTales)
|
136
|
+
end;
|
137
|
+
ENDOFMUSTBEMETHODS
|
138
|
+
|
139
|
+
|
140
|
+
mustbeMethodCompareText = <<-'ENDOFMETHOD'
|
141
|
+
def mustbe_MUSTBE_NAME_or_croak(arg1, arg2, *args)
|
142
|
+
eye = :MUSTBE_NAME
|
143
|
+
arg1.is_a?(arg2.class) || contract_exception(arg1, "DIFFERNT CLASSES arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<", *args)
|
144
|
+
argC = (arg1 MUSTBE_SPEC arg2)
|
145
|
+
# puts "<=> #{eye} argC >#{argC.class}< >#{argC}< arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<"
|
146
|
+
argC ? arg1 : contract_exception(argC, "argC >#{argC.class}< >#{argC}< arg1 >#{arg1.class}< >#{arg1}< arg2 >#{arg2.class}< >#{arg2}< opr >MUSTBE_SPEC<", *args)
|
147
|
+
end;
|
148
|
+
ENDOFMETHOD
|
149
|
+
|
150
|
+
|
151
|
+
snippetAccessor = <<-'ENDOFHERE'
|
152
|
+
def ACCESSOR_NAME
|
153
|
+
@ACCESSOR_NAME ||= nil
|
154
|
+
end;
|
155
|
+
def ACCESSOR_NAME=(value)
|
156
|
+
@ACCESSOR_NAME = value
|
157
|
+
end;
|
158
|
+
ENDOFHERE
|
159
|
+
|
160
|
+
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
|
+
def ACCESSOR_NAME=(value)
|
171
|
+
@ACCESSOR_NAME = mustbe_ACCESSOR_CONTRACT_or_croak(value, :s_ACCESSOR_NAME, "value not ACCESSOR_CONTRACT")
|
172
|
+
end;
|
173
|
+
alias_method :'set_ACCESSOR_NAME', :'ACCESSOR_NAME='
|
174
|
+
alias_method :'get_ACCESSOR_NAME', :'ACCESSOR_NAME'
|
175
|
+
ENDOFHERE
|
176
|
+
|
177
|
+
accessorEdits = {
|
178
|
+
'MUSTBE_NAME' => 'ACCESSOR_NAME',
|
179
|
+
'MUSTBE_SPEC' => 'ACCESSOR_CONTRACT',
|
180
|
+
'MUSTBE_KEYS' => 'ACCESSOR_KEYS',
|
181
|
+
}
|
182
|
+
|
183
|
+
valueisnilresultEdits = {VALUE_IS_NIL_RESULT: 'false'} # default for typed collections is not ok if nil
|
184
|
+
|
185
|
+
packageMustbeText = [mustbeMethodOneArgText, mustbeMethodKeyText, mustbeCommonText, isvalueMethodText, isvaluevalueisAliasText].flatten.join
|
186
|
+
|
187
|
+
packageAccessorSpec = [snippetAccessor].flatten
|
188
|
+
|
189
|
+
packageAccessorWithContractBaseSpec = [mustbeMethodOneArgText, mustbeMethodKeyText, mustbeMethodOneArgOrNilText, isvaluevalueisAliasText].flatten
|
190
|
+
packageAccessorWithContractSpec = [isvalueMethodText, packageAccessorWithContractBaseSpec].flatten
|
191
|
+
packageAccessorWithContractNoIsValueSpec = packageAccessorWithContractBaseSpec
|
192
|
+
|
193
|
+
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)
|
196
|
+
|
197
|
+
dynamicMethodTexts = {
|
198
|
+
|
199
|
+
# accessors
|
200
|
+
|
201
|
+
package_accessor: packageAccessorText,
|
202
|
+
package_accessor_with_contract: packageAccessorWithContractText,
|
203
|
+
package_accessor_with_contract_no_is_value: packageAccessorWithContractNoIsValueText,
|
204
|
+
|
205
|
+
method_accessor_is_value_collection_with_keys: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluecollectionwithkeysMethodText)},
|
206
|
+
method_accessor_is_value_typed_collection: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionMethodText)},
|
207
|
+
method_accessor_is_value_typed_collection_with_keys: {edit: valueisnilresultEdits, spec: Potrubi::Mixin::Dynamic::dynamic_apply_edits(accessorEdits, isvaluetypedcollectionwithkeysMethodText)},
|
208
|
+
|
209
|
+
# contracts
|
210
|
+
|
211
|
+
package_mustbe: packageMustbeText,
|
212
|
+
method_mustbe_one_arg_or_nil: mustbeMethodOneArgOrNilText,
|
213
|
+
method_mustbe_one_arg: mustbeMethodOneArgText,
|
214
|
+
method_mustbe_two_arg: mustbeMethodTwoArgText,
|
215
|
+
method_mustbe_key: mustbeMethodKeyText,
|
216
|
+
method_mustbe_one_arg_or_nil: mustbeMethodOneArgOrNilText,
|
217
|
+
|
218
|
+
method_mustbe_is_value_collection_with_keys: {edit: valueisnilresultEdits, spec: isvaluecollectionwithkeysMethodText},
|
219
|
+
method_mustbe_is_value_typed_collection: {edit: valueisnilresultEdits, spec: isvaluetypedcollectionMethodText},
|
220
|
+
|
221
|
+
method_mustbe_is_value_hash_with_keys: {edit: valueisnilresultEdits, spec: isvaluecollectionwithkeysMethodText},
|
222
|
+
method_mustbe_is_value_typed_hash: {edit: valueisnilresultEdits, spec: isvaluetypedcollectionMethodText},
|
223
|
+
|
224
|
+
method_mustbe_is_value_typed_array: {edit: valueisnilresultEdits, spec: [isvaluetypedarrayMethodText, mustbeArrayWithProcText]},
|
225
|
+
|
226
|
+
method_mustbe_is_value_typed_collection_with_keys: {edit: valueisnilresultEdits, spec: isvaluetypedcollectionwithkeysMethodText},
|
227
|
+
|
228
|
+
method_mustbe_hash_with_proc: mustbeHashWithProcText,
|
229
|
+
method_mustbe_array_with_proc: mustbeArrayWithProcText,
|
230
|
+
method_mustbe_one_arg_or_nil_with_proc: mustbeMethodOneArgOrNilWithProcText,
|
231
|
+
method_mustbe_subset: mustbeMethodSubsetText,
|
232
|
+
method_mustbe_compare: mustbeMethodCompareText,
|
233
|
+
|
234
|
+
method_mustbe_collections: mustbeMethodCollectionsText,
|
235
|
+
|
236
|
+
# assertion
|
237
|
+
|
238
|
+
method_is_value: isvalueMethodText,
|
239
|
+
|
240
|
+
# aliases
|
241
|
+
|
242
|
+
alias_is_value_value_is: isvaluevalueisAliasText,
|
243
|
+
|
244
|
+
# testing
|
245
|
+
|
246
|
+
test1: 'def ACCESSOR_NAME(testValue); IS_VALUE_TEST ? 99 : nil; end;',
|
247
|
+
}
|
248
|
+
|
249
|
+
dynamicMethodTexts # return value
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
__END__
|
254
|
+
|