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 ADDED
@@ -0,0 +1,9 @@
1
+ # potrubi #
2
+
3
+ *Plumbing for Ruby*
4
+
5
+ A collection of mixins for common Ruby programming needs
6
+
7
+ Regreatably the only documenation at this stage is the auto-generated gem pages.
8
+
9
+ *potrubi* is the Czech word for plumbing
data/lib/potrubi.rb ADDED
@@ -0,0 +1,9 @@
1
+
2
+ # Potrubi
3
+
4
+ gemName = 'potrubi'
5
+
6
+ requireList = %w(bootstrap)
7
+ requireList.each {|r| require_relative "#{gemName}/#{r}"}
8
+
9
+ __END__
@@ -0,0 +1,27 @@
1
+
2
+ # Potrubi Bootstrap Mixin
3
+
4
+ requireList = %w(logger bootstrap_common)
5
+ requireList.each {|r| require_relative "mixin/#{r}"}
6
+
7
+ mixinContent = Module.new do
8
+
9
+ # Include the mixins becuase of class method usage
10
+
11
+ includeList = [Potrubi::Mixin::Logger,
12
+ Potrubi::Mixin::BootstrapCommon,
13
+ ]
14
+ includeList.each {|n| include n}
15
+
16
+ end
17
+
18
+ module Potrubi
19
+ module Bootstrap
20
+ end
21
+ end
22
+
23
+ Potrubi::Bootstrap.__send__(:include, mixinContent) # Instance Methods
24
+ Potrubi::Bootstrap.extend(mixinContent) # Class Methods
25
+
26
+ __END__
27
+
@@ -0,0 +1,33 @@
1
+
2
+ # Core Mixin
3
+
4
+ require_relative 'bootstrap'
5
+
6
+ requireList = %w(dynamic text-snippets exception contract konstant pathandnames)
7
+ requireList.each {|r| require_relative "mixin/#{r}"}
8
+
9
+ mixinContent = Module.new do
10
+
11
+ # Include the mixins becuase of class method usage
12
+
13
+ includeList = [Potrubi::Bootstrap,
14
+ Potrubi::Mixin::Dynamic,
15
+ Potrubi::Mixin::Exception,
16
+ Potrubi::Mixin::Contract,
17
+ Potrubi::Mixin::Konstant,
18
+ Potrubi::Mixin::PathAndNames,
19
+ ]
20
+ includeList.each {|n| include n}
21
+
22
+ end
23
+
24
+ module Potrubi
25
+ module Core
26
+ end
27
+ end
28
+
29
+ Potrubi::Core.__send__(:include, mixinContent) # Instance Methods
30
+ Potrubi::Core.extend(mixinContent) # Module Methods
31
+
32
+ __END__
33
+
@@ -0,0 +1,197 @@
1
+
2
+ # potrubi klass
3
+
4
+ # syntax braket
5
+
6
+ defined?($DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET) ||
7
+ begin
8
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET ||= nil
9
+ end
10
+
11
+ require "potrubi/core"
12
+ require 'potrubi/mixin/dynamic-recipes'
13
+
14
+ klassContent = Class.new do
15
+
16
+ include Potrubi::Core
17
+ ###include Potrubi::Mixin::DynamicRecipes
18
+
19
+ # Class Methods
20
+ # #############
21
+
22
+ def self.new_method
23
+ new(:pos_text => "\n")
24
+ end
25
+
26
+ def self.new_stanza
27
+ new(:pos_text => "\n")
28
+ end
29
+
30
+ def self.new_statement
31
+ #self.new(nil, nil)
32
+ new
33
+ end
34
+
35
+ attr_accessor :pre_text, :pos_text
36
+
37
+ def initialize(initArgs=nil)
38
+ initArgs && mustbe_hash_or_croak(initArgs, :'braket i').each {|k,v| self.__send__("#{k}=", v)}
39
+ end
40
+
41
+ def to_s
42
+ eye = :'bkt to_s'
43
+ preText = pre_text
44
+ posText = pos_text
45
+
46
+ fullText = [
47
+ defined?(@head) && head_text(preText, posText),
48
+ defined?(@midl) && midl_text(preText, posText),
49
+ defined?(@tail) && tail_text(preText, posText),
50
+ ].flatten.compact.join
51
+
52
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET && logger_ca(eye, "self >#{self.object_id}< fulText >#{fullText.class}< >\n#{fullText}\n< ")
53
+
54
+ fullText
55
+
56
+ end
57
+
58
+
59
+ def to_s_with_edits(editList=nil)
60
+ eye = :to_s_w_edt
61
+ fulText = to_s
62
+ edtText = case editList
63
+ when NilClass then fulText
64
+ when Hash, Array then Potrubi::Core.dynamic_apply_edits(editList, fullText)
65
+ else
66
+ surprise_exception(editList, eye, "editList >#{editList.whoami_debug}< is what?")
67
+ end
68
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET && logger_ca(eye, "self >#{self.object_id} edtText >\n#{edtText}\n<")
69
+ edtText
70
+ end
71
+
72
+
73
+
74
+ textMethodText =
75
+ 'def METHOD_NAME_text(preText=nil, posText=nil)
76
+ METHOD_NAMEText = defined?(@METHOD_NAME) ? (@METHOD_NAME.map {|i| [preText, i.to_s, posText]}.flatten.compact.join) : nil
77
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET && logger_ca(:METHOD_NAME_text, "self >#{self.object_id}< METHOD_NAMEText >#{METHOD_NAMEText.class}< >#{METHOD_NAMEText}<")
78
+ METHOD_NAMEText
79
+ end'
80
+
81
+
82
+ baseMethodText =
83
+ 'def push_METHOD_NAME(*args)
84
+ (@METHOD_NAME ||= []).push(*ARGS_SPEC)
85
+ self
86
+ end
87
+ alias_method :tail_METHOD_NAME, :push_METHOD_NAME
88
+ def unshift_METHOD_NAME(*args)
89
+ (@METHOD_NAME ||= []).unshift(*ARGS_SPEC)
90
+ self
91
+ end
92
+ alias_method :cons_METHOD_NAME, :unshift_METHOD_NAME
93
+ def pop_METHOD_NAME
94
+ r = defined?(@METHOD_NAME) ? @METHOD_NAME.pop : nil
95
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET && logger_ca(:pop_METHOD_NAME, "self >#{self.object_id}< r >#{r}<")
96
+ r
97
+ end
98
+ def shift_METHOD_NAME
99
+ r = defined?(@METHOD_NAME) ? @METHOD_NAME.shift : nil
100
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET && logger_ca(:shift_METHOD_NAME, "self >#{self.object_id}< r >#{r}<")
101
+ r
102
+ end'
103
+
104
+ defTextList = [textMethodText, baseMethodText]
105
+ ###puts("TEXT TEST TEXT >#{defTextList}<")
106
+
107
+ braketMethods = {
108
+ :tail => defTextList,
109
+ :head => defTextList,
110
+ :midl => defTextList,
111
+ }
112
+
113
+ Potrubi::Core.dynamic_define_methods(self, braketMethods) do |k, v|
114
+ edits = {
115
+ ARGS_SPEC: 'args.flatten(1)',
116
+ METHOD_NAME: k,
117
+ }
118
+ case v
119
+ when Hash then v.merge({edit: [edits, v[:edit]]})
120
+ else
121
+ {edit: edits, spec: v || defTextList}
122
+ end
123
+ end
124
+
125
+ aliasMethods = {
126
+ :push => :push_midl,
127
+ :pop => :pop_midl,
128
+ :shift => :shift_midl,
129
+ :unshift => :unshift_midl,
130
+ :cons => :cons_midl,
131
+ :tail => :tail_midl,
132
+ }
133
+
134
+ #Potrubi::Core.dynamic_define_methods_aliases(self, aliasMethods)
135
+ Potrubi::Mixin::DynamicRecipes.recipe_aliases(self, aliasMethods)
136
+
137
+
138
+ # Diagnostics
139
+ # ###########
140
+
141
+ def raw_debug(levelText=nil)
142
+ eye = :'braket r_dbg'
143
+
144
+ $DEBUG_POTRUBI_KLASS_SYNTAX_BRAKET &&
145
+ begin
146
+ levelString = case levelText
147
+ when NilClass then 'BRAKET'
148
+ when String, Symbol then "#{levelText}"
149
+ else
150
+ unsupported_exception(levelText, eye)
151
+ end
152
+
153
+ braketAddress = "%x" % (object_id.abs*2)
154
+
155
+ puts "#{levelString} #{braketAddress} ==>"
156
+
157
+ defined?(@head) && raw_content_debug(levelString, "head", @head)
158
+ defined?(@midl) && raw_content_debug(levelString, "midl", @midl)
159
+ defined?(@tail) && raw_content_debug(levelString, "tail", @tail)
160
+
161
+ puts "#{levelString} #{braketAddress} <=="
162
+ end
163
+
164
+ self
165
+ end
166
+
167
+ def raw_content_debug(levelString, contentName, contentData)
168
+ eye = :'braket r_cnt_dbg'
169
+
170
+ braketAddress = "%x" % (object_id.abs*2)
171
+
172
+ case contentData
173
+ when NilClass then puts "#{levelString} #{braketAddress} #{contentName.to_s.upcase} IS EMPTY"
174
+ when Array then
175
+ selfClass = self.class
176
+ contentData.each_with_index do | cV, cN |
177
+ case
178
+ when cV.is_a?(selfClass) then cV.raw_debug("#{levelString} #{braketAddress}")
179
+ else
180
+ puts "#{levelString} #{braketAddress} #{contentName.to_s.upcase} cN #{"%2d" % cN} cV >#{cV.class}< >#{cV}<"
181
+ end
182
+ end
183
+ else
184
+ surprise_exception(contentData, eye)
185
+ end
186
+
187
+ self
188
+
189
+ end
190
+
191
+ end
192
+
193
+ Potrubi::Core.assign_class_constant_or_croak(klassContent, __FILE__)
194
+
195
+ __END__
196
+
197
+
@@ -0,0 +1,125 @@
1
+
2
+ # bootstrap common methods
3
+
4
+ # This turns on or off logging from boostrap / core methods
5
+ # Normally off (nil/false)
6
+
7
+ defined?($DEBUG_POTRUBI_BOOTSTRAP) || ($DEBUG_POTRUBI_BOOTSTRAP = nil)
8
+
9
+ #$DEBUG = true # TESTING
10
+
11
+ require_relative('logger')
12
+
13
+ module Potrubi
14
+ module Mixin
15
+ module BootstrapCommon
16
+
17
+ #=begin
18
+ bootstrapLoggerMethods = {
19
+ logger: :logger_message,
20
+ logger_me: :logger_me,
21
+ logger_mx: :logger_mx,
22
+ logger_ms: :logger_ms,
23
+ logger_ca: :logger_ca,
24
+ logger_fmt_class: :logger_fmt0,
25
+ logger_fmt_who: :logger_fmt0,
26
+ logger_fmt_who_only: :logger_fmt00,
27
+ }
28
+
29
+ bootstrapLoggerText = bootstrapLoggerMethods.map do | bootMethod, loggerMethod |
30
+ text = <<-"ENDOFHERE"
31
+ def potrubi_bootstrap_#{bootMethod}(*a, &b)
32
+ #puts("BOOTLOGR POTRUBI DEBUG >#{$DEBUG_POTRUBI_BOOTSTRAP.class}< >#{$DEBUG_POTRUBI_BOOTSTRAP}<")
33
+ #puts("BOOTLOGR DEBUG >#{$DEBUG.class}< >#{$DEBUG}<")
34
+ $DEBUG_POTRUBI_BOOTSTRAP && #{loggerMethod}(*a, &b)
35
+ end;
36
+ ENDOFHERE
37
+ end.compact.flatten.join("\n")
38
+
39
+ ###puts("bootstrapLoggerText >\n#{bootstrapLoggerText}")
40
+
41
+ self.module_eval(bootstrapLoggerText)
42
+ #=end
43
+
44
+ def potrubi_bootstrap_raise_exception(exception, value, *tellTales)
45
+ #tellTale = potrubi_bootstrap_logger_format_telltales(*tellTales)
46
+ tellTale = tellTales.flatten.compact.join(' ')
47
+ raise(exception,"Potrubi Bootstrap Exception value >#{value.class}< >#{value}< #{tellTale}",caller)
48
+ end
49
+
50
+ def potrubi_bootstrap_surprise_exception(value, *tellTales)
51
+ potrubi_bootstrap_raise_exception(ArgumentError, value, "value was a surpise", *tellTales)
52
+ end
53
+
54
+ def potrubi_bootstrap_unsupported_exception(value, *tellTales)
55
+ potrubi_bootstrap_raise_exception(ArgumentError, value, "value not supported", *tellTales)
56
+ end
57
+
58
+ def potrubi_bootstrap_missing_exception(value, *tellTales)
59
+ potrubi_bootstrap_raise_exception(ArgumentError, value, "value missing", *tellTales)
60
+ end
61
+
62
+ def potrubi_bootstrap_mustbe_hash_or_croak(testValue, *tellTales)
63
+ testValue.is_a?(Hash) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not hash", tellTales)
64
+ end
65
+
66
+ def potrubi_bootstrap_mustbe_array_or_croak(testValue, *tellTales)
67
+ testValue.is_a?(Array) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not array", tellTales)
68
+ end
69
+
70
+ def potrubi_bootstrap_mustbe_module_or_croak(testValue, *tellTales)
71
+ testValue.is_a?(Module) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not module", tellTales)
72
+ end
73
+
74
+ def potrubi_bootstrap_mustbe_class_or_croak(testValue, *tellTales)
75
+ testValue.is_a?(Class) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not class", tellTales)
76
+ end
77
+
78
+ def potrubi_bootstrap_mustbe_proc_or_croak(testValue, *tellTales)
79
+ testValue.is_a?(Proc) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not proc", tellTales)
80
+ end
81
+
82
+ def potrubi_bootstrap_mustbe_string_or_croak(testValue, *tellTales)
83
+ testValue.is_a?(String) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not string", tellTales)
84
+ end
85
+
86
+ def potrubi_bootstrap_mustbe_file_or_croak(testValue, *tellTales)
87
+ File.file?(testValue) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not file", tellTales)
88
+ end
89
+
90
+ def potrubi_bootstrap_mustbe_directory_or_croak(testValue, *tellTales)
91
+ File.directory?(testValue) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "value not directory", tellTales)
92
+ end
93
+
94
+ def potrubi_bootstrap_mustbe_key_or_croak(testValue, keyName, *tellTales)
95
+ (testValue.respond_to?(:has_key?) && testValue.has_key?(keyName)) ? testValue[keyName] : potrubi_bootstrap_raise_exception(ArgumentError, keyName, "testValue >#{testValue}< keyName not found", tellTales)
96
+ end
97
+
98
+ def potrubi_bootstrap_mustbe_not_nil_or_croak(testValue, *tellTales)
99
+ testValue || potrubi_bootstrap_raise_exception(ArgumentError, testValue, "testValue >#{testValue}< failed not nil ", tellTales)
100
+ end
101
+
102
+ def potrubi_bootstrap_mustbe_not_empty_or_croak(testValue, *tellTales)
103
+ (testValue.respond_to?(:empty?) && (! testValue.empty?)) ? testValue : potrubi_bootstrap_raise_exception(ArgumentError, testValue, "testValue >#{testValue}< failed not empty", tellTales)
104
+ end
105
+
106
+ def bootstrap_find_module_constant(*a)
107
+ bootstrap_find_module_constant_or_croak(*a) rescue nil
108
+ end
109
+
110
+ def bootstrap_find_module_constant_or_croak(*modNames)
111
+ #potrubi_bootstrap_mustbe_module_or_croak(modNames.flatten.compact.inject(Object) {|s,m| (s && s.const_defined?(m, false)) ? s.const_get(m) : nil})
112
+ potrubi_bootstrap_mustbe_module_or_croak(modNames.flatten.compact.join('::').split('::').inject(Object) {|s,m| (s && s.const_defined?(m, false)) ? s.const_get(m) : nil})
113
+ end
114
+
115
+ def bootstrap_find_class_constant(*a)
116
+ bootstrap_find_class_constant_or_croak(*a) rescue nil
117
+ end
118
+
119
+ def bootstrap_find_class_constant_or_croak(*a)
120
+ potrubi_bootstrap_mustbe_class_or_croak(bootstrap_find_module_constant_or_croak(*a))
121
+ end
122
+
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,109 @@
1
+
2
+ # potrubi mixin configuration
3
+
4
+ # support configuration from YAML and Ruby file
5
+
6
+ require_relative '../core'
7
+
8
+ requireList = %w(util persistence)
9
+ requireList.each {|r| require_relative "#{r}"}
10
+
11
+ ###require 'yaml'
12
+
13
+ mixinContent = Module.new do
14
+
15
+ include Potrubi::Mixin::Util
16
+ include Potrubi::Mixin::Persistence
17
+
18
+ # so common
19
+
20
+ def set_attributes_or_croak(attrArgsNom, &attrBlok)
21
+ eye = :'s_attrs'
22
+ mustbe_hash_or_croak(attrArgsNom, eye)
23
+ attrArgsNrm = Kernel.block_given? ? potrubi_util_apply_proc_to_hash_or_croak(attrArgsNom, &attrBlok) : attrArgsNom
24
+ attrArgsNrm.each {|k,v| __send__("#{k}=", v) }
25
+ ###puts("SET ATTRS attrArgs >#{attrArgs}<")
26
+ self
27
+ end
28
+
29
+ def set_attributes_from_configuration_sources_list_or_croak(*srceArgs, &srceBlok)
30
+ eye = 's_attr_fr_cfg_srcs_lst'
31
+
32
+ $DEBUG && logger_me(eye, logger_fmt_kls(srceArgs: srceArgs, srceBlok: srceBlok))
33
+
34
+ srceArgs.each { | srceArg | set_attributes_or_croak(read_configuration_source_or_croak(srceArg, &srceBlok)) }
35
+
36
+ $DEBUG && logger_mx(eye, logger_fmt_kls(srceArgs: srceArgs, srceBlok: srceBlok))
37
+
38
+ self
39
+ end
40
+
41
+
42
+ # If has key value is external source e.g. yaml
43
+ # read it and set_attributes with it
44
+ # Else raise exception unless blok is given
45
+
46
+ def set_attributes_from_configuration_sources_or_croak(srceArgs, &srceBlok)
47
+ eye = :s_attrs_fr_cfg_srces
48
+
49
+ $DEBUG && logger_me(eye, logger_fmt_kls_only(srceArgs: srceArgs), logger_fmt_kls(srceBlok: srceBlok))
50
+
51
+ mustbe_hash_or_croak(srceArgs, eye, "srceArgs not hash")
52
+
53
+ srceArgs.each do | srceName, srceValue |
54
+ case
55
+ when (p = is_value_configuration_source?(srceValue)) then set_attributes_or_croak(read_configuration_source_or_croak(srceValue))
56
+ else
57
+ Kernel.block_given? ? srceBlok.call(srceName, srceValue) : potrubi_bootstrap_surprise_exception(srceValue, eye, "srceName >#{srceName}< srceValue not a configuration source")
58
+ end
59
+ end
60
+
61
+ $DEBUG && logger_mx(eye, logger_fmt_kls_only(srceArgs: srceArgs), logger_fmt_kls(srceBlok: srceBlok))
62
+
63
+ self
64
+
65
+ end
66
+ alias_method :set_attributes_from_configuration_files_or_croak, :set_attributes_from_configuration_sources_or_croak
67
+
68
+
69
+ def set_attributes_using_specification_or_croak(attrSpec, attrData, &attrBlok)
70
+ eye = :'s_attrs_using_spec'
71
+
72
+ $DEBUG && logger_me(eye, logger_fmt_kls(attrSpec: attrSpec, attrBlok: attrBlok), logger_fmt_kls(attrData: attrData))
73
+
74
+ mustbe_hash_or_croak(attrSpec, eye, "attrSpec failed contract")
75
+ mustbe_hash_or_croak(attrData, eye, "attrData failed contract")
76
+
77
+ attrData.each do | attrName, attrValue |
78
+
79
+ #attrProc = mustbe_key_or_nil_or_croak(attrSpec, attrName, eye, "attrName >#{attrName}< not in attrSpec >#{attrSpec}<")
80
+ attrProc = attrSpec[attrName]
81
+
82
+ $DEBUG && logger_ms(eye, 'WHAT ATTR', logger_fmt_kls(attrName: attrName, attrProc: attrProc), logger_fmt_kls(attrValue: attrValue))
83
+
84
+ case attrProc
85
+ when NilClass then
86
+ $DEBUG && logger_ms(eye, 'SEND ATTR', logger_fmt_kls(attrName: attrName, attrProc: attrProc), logger_fmt_kls(attrValue: attrValue))
87
+ self.__send__("#{attrName}=", attrValue)
88
+ when Proc then
89
+ $DEBUG && logger_ms(eye, 'PROC ATTR', logger_fmt_kls(attrName: attrName, attrProc: attrProc), logger_fmt_kls(attrValue: attrValue))
90
+ instance_exec(attrName, attrValue, &attrProc)
91
+ else
92
+ surprise_exception(attrProc, eye, "attrProc is what?")
93
+ end
94
+
95
+ end
96
+
97
+ $DEBUG && logger_mx(eye, logger_fmt_kls(attrSpec: attrSpec, attrBlok: attrBlok), logger_fmt_kls(attrData: attrData))
98
+
99
+ self
100
+
101
+ end
102
+
103
+ end
104
+
105
+
106
+ mixinConstant = Potrubi::Core.assign_mixin_constant_or_croak(mixinContent, :Potrubi, :Mixin, :Configuration)
107
+
108
+ __END__
109
+