potrubi 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -0
- data/lib/potrubi.rb +9 -0
- data/lib/potrubi/bootstrap.rb +27 -0
- data/lib/potrubi/core.rb +33 -0
- data/lib/potrubi/klass/syntax/braket.rb +197 -0
- data/lib/potrubi/mixin/bootstrap_common.rb +125 -0
- data/lib/potrubi/mixin/configuration.rb +109 -0
- data/lib/potrubi/mixin/contract-recipes.rb +226 -0
- data/lib/potrubi/mixin/contract.rb +105 -0
- data/lib/potrubi/mixin/dynamic-recipes.rb +100 -0
- data/lib/potrubi/mixin/dynamic.rb +315 -0
- data/lib/potrubi/mixin/exception.rb +98 -0
- data/lib/potrubi/mixin/filesys.rb +89 -0
- data/lib/potrubi/mixin/initialize.rb +23 -0
- data/lib/potrubi/mixin/konstant.rb +368 -0
- data/lib/potrubi/mixin/logger.rb +178 -0
- data/lib/potrubi/mixin/pathandnames.rb +226 -0
- data/lib/potrubi/mixin/persistence.rb +192 -0
- data/lib/potrubi/mixin/script.rb +59 -0
- data/lib/potrubi/mixin/text-snippets.rb +182 -0
- data/lib/potrubi/mixin/text-snippets/methods-text-snippets.rb +254 -0
- data/lib/potrubi/mixin/util.rb +53 -0
- data/lib/potrubi/version.rb +1 -1
- metadata +27 -5
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
require_relative '../bootstrap'
|
3
|
+
|
4
|
+
requireList = %w(dynamic)
|
5
|
+
requireList.each {|r| require_relative "#{r}"}
|
6
|
+
|
7
|
+
mixinContent = Module.new do
|
8
|
+
|
9
|
+
errorMap = {
|
10
|
+
:ArgumentError => [:ContractError, :SurpriseError, :EmptyError, :NilError, :ValueError, :UnsupportedError, :SupriseError, :DuplicateError, :MissingError, :UnequalError, :SizeError, :FileNotFoundError, :FileNotWriteableError, :RequireError, :ChainError],
|
11
|
+
:RuntimeError => [:MethodError, :TraceAbort, :TraceError, :LogicError, :ConnectionError],
|
12
|
+
}
|
13
|
+
|
14
|
+
errorTexts = errorMap.map do | mainError, subErrors |
|
15
|
+
subErrors.map { | subError | "class #{subError} < #{mainError};end;\n" }
|
16
|
+
end
|
17
|
+
|
18
|
+
errorText = errorTexts.flatten.compact.join
|
19
|
+
|
20
|
+
Object.class_eval(errorText)
|
21
|
+
|
22
|
+
def raise_exception(exceptionTypeNom, *tellTales)
|
23
|
+
#puts "RAISE EXCEPTION CALLED"
|
24
|
+
exceptionTypeNrm = exceptionTypeNom.is_a?(Exception) ? exceptionTypeNom : RuntimeError # was an exxception type given? Default to Rumtime
|
25
|
+
tellTale = (exceptionTypeNrm == exceptionTypeNom) ? logger_format_telltales(*tellTales) : logger_format_telltales(exceptionTypeNom, *tellTales)
|
26
|
+
#error_message('RAISE EXCEPTION:', exceptionTypeNrm.class.name.upcase, *tellTales)
|
27
|
+
#puts caller
|
28
|
+
raise(exceptionTypeNrm,tellTale,caller)
|
29
|
+
end
|
30
|
+
|
31
|
+
def trace_exception(*tellTales)
|
32
|
+
raise_exception(RuntimeError, 'TRACE TRACE TRACE', *tellTales)
|
33
|
+
end
|
34
|
+
|
35
|
+
exceptionMethods = {
|
36
|
+
#:deprecated_method => nil,
|
37
|
+
#:wrong_class => nil,
|
38
|
+
:unsupported => nil,
|
39
|
+
:surprise => nil,
|
40
|
+
:duplicate => nil,
|
41
|
+
:missing => nil,
|
42
|
+
:contract => nil,
|
43
|
+
#:too_small => nil,
|
44
|
+
#:unequal => nil,
|
45
|
+
#:value => nil,
|
46
|
+
#:instantiation => nil,
|
47
|
+
#:unknown_attribute => nil,
|
48
|
+
#:nil => nil,
|
49
|
+
:nomethod => nil,
|
50
|
+
#:method => nil,
|
51
|
+
#:file_not_found => nil,
|
52
|
+
#:file_not_writeable => nil,
|
53
|
+
#:runtime => nil,
|
54
|
+
#:require => nil,
|
55
|
+
#:chain => nil,
|
56
|
+
:size => nil,
|
57
|
+
:empty => nil,
|
58
|
+
:connection => nil,
|
59
|
+
#:argument => nil,
|
60
|
+
}
|
61
|
+
|
62
|
+
Potrubi::Mixin::Dynamic::dynamic_define_methods(self, exceptionMethods) do | exceptionMethod, exceptionType |
|
63
|
+
|
64
|
+
excType = exceptionType || exceptionMethod
|
65
|
+
edits = {
|
66
|
+
METHOD_NAME: "#{exceptionMethod}_exception",
|
67
|
+
EXCEPTION_NAME: "#{exceptionMethod}",
|
68
|
+
EXCEPTION_TYPE: excType.to_s.split('_').map{|a| a.capitalize }.join.sub(/\Z/,'Error'),
|
69
|
+
###EYENAME: ":'exc_#{exceptionMethod}'",
|
70
|
+
}
|
71
|
+
|
72
|
+
textException = <<-'ENDOFHERE'
|
73
|
+
def METHOD_NAME(value, *args)
|
74
|
+
raise_exception(EXCEPTION_TYPE, *args, "value >#{value.class}< >#{value}<")
|
75
|
+
end;
|
76
|
+
ENDOFHERE
|
77
|
+
|
78
|
+
{edit: edits, spec: textException}
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
module Potrubi
|
85
|
+
module Mixin
|
86
|
+
module Exception
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
###Potrubi::Mixin::Exception.extend(metaclassMethods)
|
92
|
+
Potrubi::Mixin::Exception.__send__(:include, mixinContent) # Instance Methods
|
93
|
+
|
94
|
+
__END__
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
# potrubi filesystem methods
|
3
|
+
|
4
|
+
require_relative '../core'
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
#requireList = %w(bootstrap)
|
9
|
+
#requireList.each {|r| require_relative "#{r}"}
|
10
|
+
|
11
|
+
mixinContent = Module.new do
|
12
|
+
|
13
|
+
# FileSys Methods
|
14
|
+
# ###############
|
15
|
+
|
16
|
+
#=begin
|
17
|
+
def filesys_find_path_or_croak(*paths, &block)
|
18
|
+
mustbe_file_or_directory_or_croak(normalise_pathandname_paths_or_croak(*paths, &block))
|
19
|
+
end
|
20
|
+
alias_method :find_path_or_croak, :filesys_find_path_or_croak
|
21
|
+
#=end
|
22
|
+
|
23
|
+
#=begin
|
24
|
+
def filesys_find_file_or_croak(*paths, &block)
|
25
|
+
mustbe_file_or_croak(normalise_pathandname_paths_or_croak(*paths, &block))
|
26
|
+
end
|
27
|
+
alias_method :find_file_or_croak, :filesys_find_file_or_croak
|
28
|
+
#=end
|
29
|
+
|
30
|
+
#=begin
|
31
|
+
def filesys_find_directory_or_croak(*paths, &block)
|
32
|
+
mustbe_directory_or_croak(normalise_pathandname_paths_or_croak(*paths, &block))
|
33
|
+
end
|
34
|
+
alias_method :find_directory_or_croak, :filesys_find_directory_or_croak
|
35
|
+
alias_method :find_dir_or_croak, :filesys_find_directory_or_croak
|
36
|
+
#=end
|
37
|
+
|
38
|
+
#=begin
|
39
|
+
def create_filesys_path_directory_or_croak(*pathElements)
|
40
|
+
eye = :cpn_path_dir_or_croak
|
41
|
+
pathName = normalise_pathandname_paths_or_croak(*pathElements)
|
42
|
+
dirName = File.dirname(pathName)
|
43
|
+
create_filesys_directory_or_croak(dirName)
|
44
|
+
end
|
45
|
+
alias_method :create_path_directory_or_croak, :create_filesys_path_directory_or_croak
|
46
|
+
alias_method :create_path_dir_or_croak, :create_filesys_path_directory_or_croak
|
47
|
+
#=end
|
48
|
+
|
49
|
+
#=begin
|
50
|
+
def create_filesys_directory_or_croak(*pathElements)
|
51
|
+
eye = :cpn_dir_or_croak
|
52
|
+
dirName = normalise_pathandname_paths_or_croak(*pathElements)
|
53
|
+
case
|
54
|
+
when File.directory?(dirName) then dirName
|
55
|
+
when (! File.exists?(dirName)) then
|
56
|
+
FileUtils.mkdir_p(dirName)
|
57
|
+
mustbe_directory_or_croak(dirName, eye, "failed to create directory")
|
58
|
+
else
|
59
|
+
duplicate_exception(dirName, eye, "dirName already exists but not a directory")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
alias_method :create_directory_or_croak, :create_filesys_directory_or_croak
|
63
|
+
alias_method :create_dir_or_croak, :create_filesys_directory_or_croak
|
64
|
+
#=end
|
65
|
+
|
66
|
+
#=begin
|
67
|
+
def filesys_find_path_base_or_croak(*paths, &block) # without the .rb if any
|
68
|
+
fullPath = normalise_pathandname_paths_or_croak(*paths, &block)
|
69
|
+
basePath = File.join(File.dirname(fullPath), File.basename(fullPath, ".rb"))
|
70
|
+
$DEBUG && logger_ca(:f_pan_p_base, logger_fmt_who(:basePath => basePath, :fullPath => fullPath, :paths => paths))
|
71
|
+
mustbe_directory_or_croak(basePath)
|
72
|
+
end
|
73
|
+
#=end
|
74
|
+
#=begin
|
75
|
+
def filesys_find_mixin_home_or_croak(*paths, &block)
|
76
|
+
mixinPath = File.join(filesys_find_path_base_or_croak(*paths), 'mixin')
|
77
|
+
$DEBUG && logger_ca(:f_mix_home, logger_fmt_who(:mixinPath => mixinPath, :paths => paths))
|
78
|
+
mustbe_directory_or_croak(mixinPath)
|
79
|
+
end
|
80
|
+
alias_method :find_mixin_home_or_croak, :filesys_find_mixin_home_or_croak
|
81
|
+
#=end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
mixinConstant = Potrubi::Core.assign_mixin_constant_or_croak(mixinContent, :Potrubi, :Mixin, :Filesys)
|
87
|
+
|
88
|
+
__END__
|
89
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
require_relative '../core'
|
3
|
+
|
4
|
+
mixinContent = Module.new do
|
5
|
+
|
6
|
+
attr_accessor :name, :type, :parent
|
7
|
+
|
8
|
+
def initialize(initArgs=nil, &initBlok)
|
9
|
+
eye = :i_std
|
10
|
+
|
11
|
+
initArgs && mustbe_hash_or_croak(initArgs, eye).each {|k, v| __send__("#{k}=", v) }
|
12
|
+
|
13
|
+
Kernel.block_given? && instance_eval(&initBlok)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
#Potrubi::Mixin::Konstant.assign_module_constant_or_croak(mixinContent, :Potrubi, :Mixin, :Initialize)
|
20
|
+
Potrubi::Core.assign_module_constant_or_croak(mixinContent, __FILE__)
|
21
|
+
|
22
|
+
__END__
|
23
|
+
|
@@ -0,0 +1,368 @@
|
|
1
|
+
|
2
|
+
# potrubi constants methods
|
3
|
+
|
4
|
+
#require_relative '../bootstrap'
|
5
|
+
|
6
|
+
#requireList = %w(dynamic)
|
7
|
+
#requireList.each {|r| require_relative "#{r}"}
|
8
|
+
|
9
|
+
moduleContent = Module.new do
|
10
|
+
|
11
|
+
#includeList = [Potrubi::Bootstrap,
|
12
|
+
# Potrubi::Mixin::Dynamic,
|
13
|
+
# ]
|
14
|
+
#includeList.each {|n| include n}
|
15
|
+
|
16
|
+
#=begin
|
17
|
+
def normalise_module_constant_names_or_croak(*names, &nrmBlok)
|
18
|
+
eye = :nrm_mod_cnst_ns
|
19
|
+
|
20
|
+
moduleNamesNom = case
|
21
|
+
when respond_to?(:normalise_pathandname_names_to_hier_or_croak) then normalise_pathandname_names_to_hier_or_croak(*names)
|
22
|
+
else
|
23
|
+
names.flatten.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
moduleNamesNrm = Kernel.block_given? ? moduleNamesNom.map(&nrmBlok) : moduleNamesNom
|
27
|
+
|
28
|
+
potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(:names_norm => moduleNamesNrm, :names => names))
|
29
|
+
|
30
|
+
moduleNamesNrm
|
31
|
+
|
32
|
+
end
|
33
|
+
#=end
|
34
|
+
|
35
|
+
#=begin
|
36
|
+
def assign_class_constant_or_croak(classConstant, *names, &asgBlok)
|
37
|
+
r = classConstant.is_a?(Class) ? classConstant : create_class_constant_or_croak(*classConstant)
|
38
|
+
potrubi_bootstrap_mustbe_class_or_croak(assign_module_constant_or_croak(r, *names, &asgBlok))
|
39
|
+
end
|
40
|
+
alias_method :assign_class_constant, :assign_class_constant_or_croak
|
41
|
+
#=end
|
42
|
+
|
43
|
+
#=begin
|
44
|
+
def assign_module_constant_or_croak(moduleConstant, *names, &asgBlok)
|
45
|
+
eye = :asg_mod_cnst
|
46
|
+
|
47
|
+
moduleNames = normalise_module_constant_names_or_croak(*names)
|
48
|
+
###normalise_pathandname_names_to_hier_or_croak(*names)
|
49
|
+
|
50
|
+
$DEBUG_POTRUBI_BOOTSTRAP && begin
|
51
|
+
logrArgs = potrubi_bootstrap_logger_fmt_who(:constant => moduleConstant, :moduleNames => moduleNames, :names => names, :self => self)
|
52
|
+
potrubi_bootstrap_logger_me(eye, logrArgs)
|
53
|
+
end
|
54
|
+
|
55
|
+
moduleName = moduleNames.pop
|
56
|
+
|
57
|
+
###puts("#{eye} moduleName >#{moduleName}< moduleNames >#{moduleNames.class}< >#{moduleNames}<")
|
58
|
+
|
59
|
+
moduleParent = case
|
60
|
+
when moduleNames.empty? then Object
|
61
|
+
else
|
62
|
+
moduleNames.inject(Object) {| mC, mN | mC.const_defined?(mN, false) ? mC.const_get(mN) : mC.const_set(mN, Module.new)}
|
63
|
+
end
|
64
|
+
|
65
|
+
potrubi_bootstrap_mustbe_module_or_croak(moduleParent, eye)
|
66
|
+
|
67
|
+
currentConstant = moduleParent.const_defined?(moduleName, false)
|
68
|
+
|
69
|
+
currentConstant && begin
|
70
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, potrubi_bootstrap_logger_fmt_who(:moduleParent => moduleParent, :moduleName => moduleName), "exists already")
|
71
|
+
bootstrap_duplicate_exception(moduleName, "moduleName exists already")
|
72
|
+
end
|
73
|
+
|
74
|
+
#moduleParent.const_set(moduleName, moduleConstant)
|
75
|
+
moduleParent.const_set(moduleName, moduleConstant.is_a?(Module) ? moduleConstant : create_module_constant_or_croak(*moduleConstant))
|
76
|
+
|
77
|
+
moduleConstantFound = moduleParent.const_get(moduleName)
|
78
|
+
|
79
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:constant_found => moduleConstantFound), logrArgs)
|
80
|
+
|
81
|
+
potrubi_bootstrap_mustbe_module_or_croak(moduleConstantFound, eye)
|
82
|
+
|
83
|
+
end
|
84
|
+
alias_method :assign_module_constant, :assign_module_constant_or_croak
|
85
|
+
alias_method :assign_mixin_constant_or_croak, :assign_module_constant_or_croak
|
86
|
+
alias_method :assign_mixin_constant, :assign_mixin_constant_or_croak
|
87
|
+
#=end
|
88
|
+
|
89
|
+
def find_class_constant(*a, &b)
|
90
|
+
find_class_constant_or_croak(*a, &b) rescue nil
|
91
|
+
end
|
92
|
+
def find_class_constant_or_croak(*a, &b)
|
93
|
+
potrubi_bootstrap_mustbe_class_or_croak(find_module_constant_or_croak(*a, &b))
|
94
|
+
end
|
95
|
+
|
96
|
+
def find_or_require_class_constant_or_croak(*a, &b)
|
97
|
+
eye = :for_kls_con
|
98
|
+
find_class_constant(*a, &b) || begin
|
99
|
+
|
100
|
+
modNames = normalise_module_constant_names_or_croak(*a, &b)
|
101
|
+
|
102
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(:modNames => modNames))
|
103
|
+
potrubi_bootstrap_mustbe_not_empty_or_croak(modNames, eye)
|
104
|
+
|
105
|
+
requireName = File.join(*modNames.map(&:downcase))
|
106
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(:modNames => modNames, :requireName => requireName))
|
107
|
+
|
108
|
+
require requireName
|
109
|
+
|
110
|
+
find_class_constant_or_croak(*a, &b)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
def find_module_constants_or_croak(*names, &findBlok)
|
116
|
+
names.map {|n| find_module_constant_or_croak(n, &findBlok) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def find_module_constant(*a, &b)
|
120
|
+
find_module_constant_or_croak(*a, &b) rescue nil
|
121
|
+
end
|
122
|
+
def find_module_constant_or_croak(*names, &findBlok)
|
123
|
+
eye = :f_mod_cnst
|
124
|
+
|
125
|
+
###modNames = names.flatten.compact
|
126
|
+
modNames = normalise_module_constant_names_or_croak(*names)
|
127
|
+
|
128
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(:modNames => modNames))
|
129
|
+
potrubi_bootstrap_mustbe_not_empty_or_croak(modNames, eye)
|
130
|
+
|
131
|
+
modCon = case
|
132
|
+
when modNames.empty? then Object
|
133
|
+
when (modNames.size == 1) && (modNames.first.is_a?(Module)) then modNames.first # nothing to do
|
134
|
+
else
|
135
|
+
modNames.join('::').split('::').inject(Object) do | mC, mN |
|
136
|
+
potrubi_bootstrap_mustbe_module_or_croak(mC, eye, "mC not module mN >#{mN}<")
|
137
|
+
###puts("#{eye} INJ mC >#{mC.class}< >#{mC}< mN >#{mN.class}< >#{mN}<");
|
138
|
+
mC.const_defined?(mN, false) ? mC.const_get(mN) : nil
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "modCon >#{modCon.class}< >#{modCon}< modNames >#{modNames}<")
|
143
|
+
|
144
|
+
#modCon.is_a?(Module) ? modCon : raise(ArgumentError, "#{eye} modCon >#{modCon.class}< >#{modCon}< not Module")
|
145
|
+
potrubi_bootstrap_mustbe_module_or_croak(modCon)
|
146
|
+
|
147
|
+
modResult = Kernel.block_given? ? findBlok.call(modCon) : modCon
|
148
|
+
|
149
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, potrubi_bootstrap_logger_fmt_who(:modResult => modResult, :modCon => modCon, :modNames => modNames))
|
150
|
+
|
151
|
+
modResult # can not tell what this could be as block could do anything
|
152
|
+
|
153
|
+
end
|
154
|
+
alias_method :find_mixin_constant_or_croak, :find_module_constant_or_croak
|
155
|
+
|
156
|
+
|
157
|
+
#begin
|
158
|
+
def find_peer_class_constant_or_croak(*peerNames)
|
159
|
+
thisHier = self.class.name.split('::')
|
160
|
+
thisHier.pop
|
161
|
+
find_class_constant_or_croak(thisHier, peerNames)
|
162
|
+
end
|
163
|
+
#=end
|
164
|
+
|
165
|
+
#=begin
|
166
|
+
def create_class_constant_or_croak(*names, &cratBlok)
|
167
|
+
initValue = names.flatten.first.is_a?(Class) ? nil : Class.new # Must ALWAYS have a class first
|
168
|
+
potrubi_bootstrap_mustbe_class_or_croak(create_module_constant_or_croak(initValue, *names, &cratBlok))
|
169
|
+
end
|
170
|
+
alias_method :enhance_class_constant_or_croak, :create_class_constant_or_croak
|
171
|
+
|
172
|
+
#=begin
|
173
|
+
def create_module_constant_or_croak(*names, &cratBlok)
|
174
|
+
eye = :cr_mod_cnst
|
175
|
+
|
176
|
+
moduleNames = names
|
177
|
+
|
178
|
+
logrArgs = potrubi_bootstrap_logger_fmt_who(:names => moduleNames)
|
179
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, logrArgs)
|
180
|
+
|
181
|
+
#moduleName = moduleNames.pop
|
182
|
+
moduleConstants = normalise_module_contents_or_croak(*moduleNames)
|
183
|
+
|
184
|
+
moduleConstantFirst = moduleConstants.first
|
185
|
+
|
186
|
+
moduleInitValue = case moduleConstantFirst
|
187
|
+
when Class then moduleConstants.shift # Must use the class as the init value to inject
|
188
|
+
when Module then Module.new # start from scratch
|
189
|
+
else
|
190
|
+
logic_exception(moduleConstantFirst, eye, "moduleConstantFirst is what?")
|
191
|
+
end
|
192
|
+
|
193
|
+
moduleConstant = moduleConstants.inject(moduleInitValue) { | wC, mC | wC.__send__(:include, mC) }
|
194
|
+
|
195
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:constant => moduleConstant, :includes => moduleConstants), logrArgs)
|
196
|
+
|
197
|
+
potrubi_bootstrap_mustbe_module_or_croak(moduleConstant)
|
198
|
+
|
199
|
+
end
|
200
|
+
#=end
|
201
|
+
|
202
|
+
#=begin
|
203
|
+
def extend_receiver_or_croak(receiverValue, *mixinContents)
|
204
|
+
eye = :ext_rcv
|
205
|
+
eyeTale = 'EXTEND RCV'
|
206
|
+
|
207
|
+
logrArgs = dynamic_potrubi_bootstrap_logger_fmt_who(:receiver => receiverValue, :mixins => mixinContents)
|
208
|
+
|
209
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, logrArgs)
|
210
|
+
|
211
|
+
#mixinConstants = normalise_mixins_or_croak(receiverValue, nil, *mixinContents).values
|
212
|
+
#mixinConstants = mixinContents.flatten.compact.uniq.map {|m| potrubi_bootstrap_mustbe_module_or_croak(m) }
|
213
|
+
mixinConstants = normalise_mixin_contents_or_croak(*mixinContents)
|
214
|
+
|
215
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, logrArgs, potrubi_bootstrap_logger_fmt_who(:mixin_constants => mixinConstants))
|
216
|
+
|
217
|
+
value_is_empty? ||
|
218
|
+
begin
|
219
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, 'EXTENDNG', logrArgs)
|
220
|
+
|
221
|
+
mixinConstants.each do |mixinConstant|
|
222
|
+
|
223
|
+
receiverValue.extend(mixinConstant) # Add the instance methods, etc of mixin to receiver
|
224
|
+
|
225
|
+
#mixinConstantClassMethods = mixinConstant.const_get(:ClassMethods, false) rescue nil # any class methods
|
226
|
+
#potrubi_bootstrap_logger_ms(eye, eyeTale, "KLS MTDS receiverValue >#{receiverValue.class}< >#{receiverValue}< mixinConstantClassMethods >#{mixinConstantClassMethods.class}< >#{mixinConstantClassMethods}<")
|
227
|
+
#mixinConstantClassMethods && mixinConstantClassMethods.is_a?(Module) && receiverValue.instance_eval{ extend mixinConstantClassMethods } # Add the class methods of mixin to the singleton classs of receiver
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, 'EXTENDED', logrArgs)
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
|
236
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, logrArgs)
|
237
|
+
|
238
|
+
self
|
239
|
+
|
240
|
+
end
|
241
|
+
#=end
|
242
|
+
|
243
|
+
#=begin
|
244
|
+
def normalise_mixin_contents_or_croak(*nomMixins)
|
245
|
+
eye = :nrm_mxn_cnts
|
246
|
+
eyeTale = 'NRM MXN CONTENTS'
|
247
|
+
|
248
|
+
logrArgs = potrubi_bootstrap_logger_fmt_who(:nomMixins => nomMixins)
|
249
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, eyeTale, logrArgs)
|
250
|
+
|
251
|
+
nrmMixins = nomMixins.flatten(1).compact.map.with_index do | mV, mN |
|
252
|
+
|
253
|
+
logrNormArgs = potrubi_bootstrap_logger_fmt_who(:mN => mN, :mV => mV)
|
254
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, "NORMNG", logrNormArgs)
|
255
|
+
|
256
|
+
mC = case mV
|
257
|
+
when Module then mV # nothing to to
|
258
|
+
when Proc then Module.new(&mV)
|
259
|
+
when String, Symbol then find_mixin_constant_or_croak(mV)
|
260
|
+
when Array then # Array ONLY way to pass text
|
261
|
+
mVMod = Module.new
|
262
|
+
mVMod.module_eval([*mV].flatten.compact.join)
|
263
|
+
mVMod
|
264
|
+
when Hash then resolve_module_constants_or_croak(mV).values
|
265
|
+
else
|
266
|
+
potrubi_bootstrap_surprise_exception(mV,"mN >#{mN}< mV is what?")
|
267
|
+
end
|
268
|
+
|
269
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, eyeTale, "NORMED", logrNormArgs, potrubi_bootstrap_logger_fmt_who(:mC => mC))
|
270
|
+
|
271
|
+
#mC && potrubi_bootstrap_mustbe_module_or_croak(mC)
|
272
|
+
mC
|
273
|
+
|
274
|
+
end.flatten.compact
|
275
|
+
|
276
|
+
nrmMixins.each {|m| potrubi_bootstrap_mustbe_module_or_croak(m, eye) }
|
277
|
+
|
278
|
+
|
279
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, eyeTale, potrubi_bootstrap_logger_fmt_who(:nrmMixins => nrmMixins))
|
280
|
+
|
281
|
+
|
282
|
+
potrubi_bootstrap_mustbe_array_or_croak(nrmMixins, eye)
|
283
|
+
end
|
284
|
+
alias_method :normalise_module_contents_or_croak, :normalise_mixin_contents_or_croak
|
285
|
+
#=end
|
286
|
+
|
287
|
+
#=begin
|
288
|
+
def resolve_module_constants_or_croak(*resolvMaps)
|
289
|
+
eye = :rsv_mod_cons
|
290
|
+
|
291
|
+
logrArgs = potrubi_bootstrap_logger_fmt_who(:map => resolvMaps)
|
292
|
+
|
293
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, logrArgs)
|
294
|
+
|
295
|
+
moduleConstants = resolvMaps.flatten.compact.each_with_object({}) do | resolvMap, h |
|
296
|
+
|
297
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "MOD SPEC", potrubi_bootstrap_logger_fmt_who(:rsv_map => resolvMap))
|
298
|
+
|
299
|
+
potrubi_bootstrap_mustbe_hash_or_croak(resolvMap)
|
300
|
+
|
301
|
+
r = case
|
302
|
+
when resolvMap.has_key?(:requires) then
|
303
|
+
requireNames = [*resolvMap[:requires]].flatten.compact
|
304
|
+
requirePath = resolvMap[:path]
|
305
|
+
requirePath && potrubi_bootstrap_mustbe_directory_or_croak(requirePath)
|
306
|
+
requirePaths = requirePath ? requireNames.each_with_object({}) {|n,h| h[n] = File.join(requirePath, n) } : requireNames.each_with_object({}) {|n,h| h[n] = n}
|
307
|
+
|
308
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, 'REQUIRES', potrubi_bootstrap_logger_fmt_who(:paths => requirePaths, :names => requireNames, :path => requirePath))
|
309
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, 'LOADED FEATURES', potrubi_bootstrap_logger_fmt_who(:loaded => $LOADED_FEATURES))
|
310
|
+
|
311
|
+
#potrubi_bootstrap_trace_exception(eye,"REQUIRES HOLD HERE X1")
|
312
|
+
|
313
|
+
requirePaths.each do |n, p|
|
314
|
+
case
|
315
|
+
when $LOADED_FEATURES.include?(p) then nil
|
316
|
+
else
|
317
|
+
r = require p
|
318
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ms(eye, "REQUIRED", potrubi_bootstrap_logger_fmt_who(:n => n, :p => p, :r => r))
|
319
|
+
potrubi_bootstrap_mustbe_not_nil_or_croak(r, eye, "n >#{n} p >#{p}< require failed >#{r.class}< >#{r}<")
|
320
|
+
r
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
potrubi_bootstrap_trace_exception(eye,"REQUIRES HOLD HERE X2")
|
325
|
+
|
326
|
+
when resolvMap.has_key?(:mixins) then
|
327
|
+
mixinNames = [*resolvMap[:mixins]].flatten.compact
|
328
|
+
mixinParent = potrubi_bootstrap_mustbe_key_or_croak(resolvMap, :relative)
|
329
|
+
else
|
330
|
+
potrubi_bootstrap_surprise_exception(resolvMap, eye, "resolveMap does not have any know keys")
|
331
|
+
end
|
332
|
+
|
333
|
+
###when Module then resolvMap # nothing to do
|
334
|
+
###when String, Symbol, Array then bootstrap_find_module_constant_or_croak(resolvMap)
|
335
|
+
|
336
|
+
###else
|
337
|
+
### potrubi_bootstrap_surprise_exception(resolvMap, eye, "resolvMap is what?")
|
338
|
+
###end
|
339
|
+
|
340
|
+
r && (h[resolvMap] = r)
|
341
|
+
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
|
346
|
+
$DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(:constants => moduleConstants), logrArgs)
|
347
|
+
|
348
|
+
moduleConstants
|
349
|
+
end
|
350
|
+
#=end
|
351
|
+
|
352
|
+
end
|
353
|
+
|
354
|
+
# Make the methods both instance and class
|
355
|
+
|
356
|
+
module Potrubi
|
357
|
+
module Mixin
|
358
|
+
module Konstant
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
###Potrubi::Mixin::Konstant.extend(moduleContent)
|
364
|
+
Potrubi::Mixin::Konstant.__send__(:include, moduleContent) # Instance Methods
|
365
|
+
|
366
|
+
__END__
|
367
|
+
|
368
|
+
|