potrubi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/lib/potrubi.rb +1 -1
  2. data/lib/potrubi/bootstrap.rb +1 -1
  3. data/lib/potrubi/core.rb +3 -3
  4. data/lib/potrubi/dsl.rb +86 -0
  5. data/lib/potrubi/dsl/accessor.rb +76 -0
  6. data/lib/potrubi/dsl/cache_2d.rb +811 -0
  7. data/lib/potrubi/dsl/contract.rb +731 -0
  8. data/lib/potrubi/dsl/super.rb +517 -0
  9. data/lib/potrubi/klass/syntax/alias.rb +150 -0
  10. data/lib/potrubi/klass/syntax/braket.rb +115 -25
  11. data/lib/potrubi/klass/syntax/builder.rb +45 -0
  12. data/lib/potrubi/klass/syntax/method.rb +436 -0
  13. data/lib/potrubi/klass/syntax/mixin/name_generation.rb +85 -0
  14. data/lib/potrubi/klass/syntax/mixin/new_aliases.rb +76 -0
  15. data/lib/potrubi/klass/syntax/mixin/new_brakets.rb +89 -0
  16. data/lib/potrubi/klass/syntax/mixin/new_methods.rb +158 -0
  17. data/lib/potrubi/klass/syntax/mixin/new_snippets.rb +74 -0
  18. data/lib/potrubi/klass/syntax/mixin/new_statements.rb +0 -0
  19. data/lib/potrubi/klass/syntax/mixin/statement_management.rb +69 -0
  20. data/lib/potrubi/klass/syntax/mixin/synel_management.rb +168 -0
  21. data/lib/potrubi/klass/syntax/snippet.rb +386 -0
  22. data/lib/potrubi/klass/syntax/statement.rb +91 -0
  23. data/lib/potrubi/klass/syntax/super.rb +88 -0
  24. data/lib/potrubi/mixin/bootstrap_common.rb +38 -12
  25. data/lib/potrubi/mixin/configuration.rb +31 -3
  26. data/lib/potrubi/mixin/contract.rb +5 -14
  27. data/lib/potrubi/mixin/contract/recipes.rb +307 -0
  28. data/lib/potrubi/mixin/dynamic-recipes.rb +1 -11
  29. data/lib/potrubi/mixin/dynamic.rb +223 -115
  30. data/lib/potrubi/mixin/exception.rb +3 -22
  31. data/lib/potrubi/mixin/filesys.rb +5 -21
  32. data/lib/potrubi/mixin/initialize.rb +11 -6
  33. data/lib/potrubi/mixin/konstant.rb +14 -118
  34. data/lib/potrubi/mixin/logger.rb +28 -41
  35. data/lib/potrubi/mixin/pathandnames.rb +4 -34
  36. data/lib/potrubi/mixin/persistence.rb +115 -10
  37. data/lib/potrubi/mixin/script.rb +0 -5
  38. data/lib/potrubi/mixin/{text-snippets → snippet-dictionaries}/methods-text-snippets.rb +138 -49
  39. data/lib/potrubi/mixin/{text-snippets.rb → snippet-manager.rb} +51 -39
  40. data/lib/potrubi/mixin/util.rb +66 -20
  41. data/lib/potrubi/version.rb +1 -1
  42. data/test/potrubi/mixin/bootstrap_common.rb +205 -0
  43. data/test/potrubi/mixin/konstant.rb +216 -0
  44. data/test/potrubi/mixin/logger.rb +124 -0
  45. data/test/ts_bootstrap_mixins.rb +16 -0
  46. data/test/ts_core_mixins.rb +7 -0
  47. metadata +31 -6
  48. data/lib/potrubi/mixin/contract-recipes.rb +0 -226
@@ -0,0 +1,124 @@
1
+
2
+ # Potrubi Test Logger Mixin
3
+
4
+ require 'minitest/autorun'
5
+ require 'minitest/spec'
6
+
7
+
8
+ require 'potrubi/mixin/logger'
9
+
10
+ class TestClass1
11
+
12
+ include Potrubi::Mixin::Logger
13
+
14
+ end
15
+
16
+ describe TestClass1 do
17
+
18
+ before do
19
+ @mixConstant = Potrubi::Mixin::Logger
20
+ @t = TestClass1.new
21
+ @validClassMethods = [:logger,
22
+ :new_logger,
23
+ ]
24
+
25
+ @validInstanceMethods = [:logger_fmt,
26
+ :logger_message,
27
+ :logger_method_entry,
28
+ :logger_method_exit,
29
+ :logger_method_call,
30
+ :logger_instance_telltale,
31
+ ]
32
+
33
+ end
34
+
35
+ describe 'mixin reponds to only module methods' do
36
+
37
+ it 'has valid module methods' do
38
+ @validClassMethods.each { | methodName | @mixConstant.must_respond_to methodName }
39
+ end
40
+
41
+ it 'mixin doesnt repond to instance methods' do
42
+ @validInstanceMethods.each { | methodName | @mixConstant.wont_respond_to methodName }
43
+ end
44
+
45
+
46
+ end
47
+
48
+ describe 'class reponds to instance methods' do
49
+
50
+ it 'has valid instance methods' do
51
+ @validInstanceMethods.each { | methodName | @t.must_respond_to methodName }
52
+ end
53
+
54
+ end
55
+
56
+ describe 'format messages' do
57
+
58
+ it 'formats telltales ok' do
59
+ tellTales = {
60
+ 'x' => :x,
61
+ '1' => 1,
62
+ 'a b c' => %w(a b c),
63
+ 'Hello Mum' => [:Hello, :Mum],
64
+ 'Ruby is the Biz!' => [:Ruby, [:is, :the], 'Biz!'],
65
+ }
66
+ tellTales.each do | wantText, tellTale |
67
+ @t.logger_format_telltales(tellTale).must_equal wantText
68
+ end
69
+
70
+ end
71
+
72
+ it 'formats the instance telltales ok' do
73
+
74
+ basetellTale = "(%x)" % (@t.object_id.abs*2)
75
+
76
+ instanceTellTales = [
77
+ [nil, "I#{basetellTale}"],
78
+ ['ABC', "ABC#{basetellTale}"],
79
+ [nil, "ABC#{basetellTale}"],
80
+ [:xyz, "xyz#{basetellTale}"],
81
+ [nil, "xyz#{basetellTale}"],
82
+ ]
83
+
84
+
85
+
86
+ instanceTellTales.each do | (prefix, instanceTellTale) |
87
+ @t.logger_instance_telltale(prefix).must_equal instanceTellTale
88
+ end
89
+
90
+
91
+ end
92
+
93
+
94
+ end
95
+
96
+
97
+ end
98
+
99
+
100
+ __END__
101
+
102
+
103
+ class TestLogger < MiniTest::Unit::TestCase
104
+ def setup
105
+ @logger = Potrubi:
106
+ @meme = Meme.new
107
+ end
108
+
109
+ def test_that_kitty_can_eat
110
+ assert_equal "OHAI!", @meme.i_can_has_cheezburger?
111
+ end
112
+
113
+ def test_that_it_will_not_blend
114
+ refute_match /^no/i, @meme.will_it_blend?
115
+ end
116
+
117
+ def test_that_will_be_skipped
118
+ skip "test this later"
119
+ end
120
+ end
121
+
122
+ __END__
123
+
124
+
@@ -0,0 +1,16 @@
1
+ #require 'minitest/spec'
2
+ require 'minitest'
3
+ require 'minitest/autorun'
4
+
5
+ # Potrubi Bootstrap Mixins Suite
6
+
7
+ $DEBUG_POTRUBI_BOOTSTRAP = true
8
+
9
+ require './test/potrubi/mixin/logger'
10
+ require './test/potrubi/mixin/bootstrap_common'
11
+
12
+
13
+
14
+
15
+ #require 'potrubi/mixin/logger'
16
+ #require 'potrubi/mixin/bootstrap_common'
@@ -0,0 +1,7 @@
1
+ #require 'minitest/spec'
2
+ require 'minitest'
3
+ require 'minitest/autorun'
4
+
5
+ # Potrubi Core Mixins Test Suite
6
+
7
+ require './test/potrubi/mixin/konstant'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potrubi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-15 00:00:00.000000000 Z
12
+ date: 2015-02-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Potrubi: A collection of Ruby mixins for common needs'
15
15
  email:
@@ -22,11 +22,30 @@ files:
22
22
  - lib/potrubi.rb
23
23
  - lib/potrubi/bootstrap.rb
24
24
  - lib/potrubi/core.rb
25
+ - lib/potrubi/dsl.rb
26
+ - lib/potrubi/dsl/accessor.rb
27
+ - lib/potrubi/dsl/cache_2d.rb
28
+ - lib/potrubi/dsl/contract.rb
29
+ - lib/potrubi/dsl/super.rb
30
+ - lib/potrubi/klass/syntax/alias.rb
25
31
  - lib/potrubi/klass/syntax/braket.rb
32
+ - lib/potrubi/klass/syntax/builder.rb
33
+ - lib/potrubi/klass/syntax/method.rb
34
+ - lib/potrubi/klass/syntax/mixin/name_generation.rb
35
+ - lib/potrubi/klass/syntax/mixin/new_aliases.rb
36
+ - lib/potrubi/klass/syntax/mixin/new_brakets.rb
37
+ - lib/potrubi/klass/syntax/mixin/new_methods.rb
38
+ - lib/potrubi/klass/syntax/mixin/new_snippets.rb
39
+ - lib/potrubi/klass/syntax/mixin/new_statements.rb
40
+ - lib/potrubi/klass/syntax/mixin/statement_management.rb
41
+ - lib/potrubi/klass/syntax/mixin/synel_management.rb
42
+ - lib/potrubi/klass/syntax/snippet.rb
43
+ - lib/potrubi/klass/syntax/statement.rb
44
+ - lib/potrubi/klass/syntax/super.rb
26
45
  - lib/potrubi/mixin/bootstrap_common.rb
27
46
  - lib/potrubi/mixin/configuration.rb
28
- - lib/potrubi/mixin/contract-recipes.rb
29
47
  - lib/potrubi/mixin/contract.rb
48
+ - lib/potrubi/mixin/contract/recipes.rb
30
49
  - lib/potrubi/mixin/dynamic-recipes.rb
31
50
  - lib/potrubi/mixin/dynamic.rb
32
51
  - lib/potrubi/mixin/exception.rb
@@ -37,11 +56,16 @@ files:
37
56
  - lib/potrubi/mixin/pathandnames.rb
38
57
  - lib/potrubi/mixin/persistence.rb
39
58
  - lib/potrubi/mixin/script.rb
40
- - lib/potrubi/mixin/text-snippets.rb
41
- - lib/potrubi/mixin/text-snippets/methods-text-snippets.rb
59
+ - lib/potrubi/mixin/snippet-dictionaries/methods-text-snippets.rb
60
+ - lib/potrubi/mixin/snippet-manager.rb
42
61
  - lib/potrubi/mixin/util.rb
43
62
  - lib/potrubi/potrubi.rb
44
63
  - lib/potrubi/version.rb
64
+ - test/potrubi/mixin/bootstrap_common.rb
65
+ - test/potrubi/mixin/konstant.rb
66
+ - test/potrubi/mixin/logger.rb
67
+ - test/ts_bootstrap_mixins.rb
68
+ - test/ts_core_mixins.rb
45
69
  homepage: https://github.com/ianrumford/potrubi
46
70
  licenses: []
47
71
  post_install_message:
@@ -65,5 +89,6 @@ rubyforge_project: potrubi
65
89
  rubygems_version: 1.8.11
66
90
  signing_key:
67
91
  specification_version: 3
68
- summary: ! 'Potrubi: plumbing for Ruby'
92
+ summary: ! 'Potrubi: Plumbing for Ruby'
69
93
  test_files: []
94
+ has_rdoc:
@@ -1,226 +0,0 @@
1
-
2
- # potrubi contract recipes
3
-
4
- # to ease the creation of contracts, accessors, etc in class bodies
5
-
6
- # These are *mixin* ('class') methods; not instance ones
7
-
8
- # Uses conventions for names etc dedined by (in) contract mixin
9
-
10
- require_relative '../bootstrap'
11
-
12
- requireList = %w(contract util)
13
- requireList.each {|r| require_relative "#{r}"}
14
-
15
- mixinContent = Module.new do
16
-
17
- include Potrubi::Bootstrap
18
- include Potrubi::Mixin::Util
19
-
20
- def standard_accessor_edit(k, v)
21
- {ACCESSOR_NAME: k, ACCESSOR_CONTRACT: k}
22
- end
23
-
24
- def standard_mustbe_edit(k, v)
25
- {MUSTBE_NAME: k, MUSTBE_SPEC: k}
26
- end
27
-
28
- # convenience methods
29
-
30
- def merge_edits(*edits)
31
- Potrubi::Mixin::Dynamic.dynamic_merge_edits(*edits)
32
- end
33
-
34
- def merge_specs(*specs)
35
- specs.flatten
36
- end
37
-
38
- def merge_spec_and_edit(spec, edit)
39
- { edit: edit, spec: spec}
40
- end
41
-
42
- # This method is peculair to accessors & mustbes
43
- # not general purpose as e.g. hash treatment makes assumptions
44
-
45
- def standard_case_statement(k, v, s, edit, spec)
46
- eye = :'rcp_std_case'
47
- r = case v
48
- when Symbol then merge_spec_and_edit(spec, merge_edits(edit, {IS_VALUE_TEST: "testValue.is_a?(#{v.to_s.capitalize})"}))
49
- when Class, String then merge_spec_and_edit(spec, merge_edits(edit, {IS_VALUE_TEST: "testValue.is_a?(#{v})"}))
50
- when NilClass then merge_spec_and_edit(spec, merge_edits(edit, {IS_VALUE_TEST: 'testValue'}))
51
- when Array then v # dynamic_define_methods will parse
52
- when Proc then
53
- [ merge_spec_and_edit(spec, merge_edits(edit, {IS_VALUE_TEST: 'false'})), # error on default isValueText
54
- {name: "is_value_#{k}?", spec: v}, # ... but override is_value method
55
- ]
56
- when Hash then merge_spec_and_edit(merge_specs([spec, v[:spec]]), merge_edits(edit, {IS_VALUE_TEST: 'false'}, v[:edit]))
57
- else
58
- potrubi_bootstrap_surprise_exception(v, eye, "accessor name >#{k}< spec not expected")
59
- end
60
- $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_ca(eye, potrubi_bootstrap_logger_fmt_who(k: k, v: v, edit: edit), potrubi_bootstrap_logger_fmt_who(spec: spec), potrubi_bootstrap_logger_fmt_who(r: r))
61
- r
62
- #STOPCASEEXIT
63
- end
64
-
65
- def standard_accessor_recipe_block(s) # returns a lambda
66
- ->(k, v) {
67
- edit = standard_accessor_edit(k, v)
68
- ###spec = {spec: s}
69
- spec = s
70
- r = standard_case_statement(k, v, s, edit, spec)
71
- #puts("\n\n\nACCE RCP BLOK r >#{r}<\n\n\n")
72
- r
73
- #STOPACCEBLOK
74
- }
75
- end
76
-
77
- def standard_mustbe_recipe_block(s) # returns a lambda
78
- ->(k, v) {
79
- edit = standard_mustbe_edit(k, v)
80
- ###spec = {spec: s}
81
- spec = s
82
- r = standard_case_statement(k, v, s, edit, spec)
83
- #puts("\n\n\nMUSTBE RCP BLOK r >#{r}<")
84
- r
85
- }
86
- end
87
-
88
-
89
- def resolve_recipe_texts(*recipeTexts)
90
- eye = :'rslv_rcp_texts'
91
-
92
- utilityText = Potrubi::Mixin::Contract::CONTRACT_TEXTS
93
-
94
- resolvedTexts = recipeTexts.flatten.map do | recipeText |
95
- puts("recipeText >#{recipeText.class}< >#{recipeText}<")
96
- case recipeText
97
- when Symbol then utilityText[recipeText]
98
- when Proc then recipeText
99
- else
100
- potrubi_bootstrap_surprise_exception(recipeText, eye, "recipeText is what?")
101
- ###recipeText
102
- end
103
- end
104
-
105
- resolvedTexts
106
-
107
- end
108
- def resolve_recipe_texts(*recipeTexts)
109
- recipeTexts.flatten
110
- end
111
-
112
-
113
- def recipe_accessors(attrTarget, attrDefs, *attrTexts, &attrBlok)
114
- eye = :'rcp_accessors'
115
-
116
- ###STOPHEREACCS
117
-
118
- #puts("K0")
119
-
120
- $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(attrTarget: attrTarget, attrDefs: attrDefs, attrTexts: attrTexts))
121
-
122
- #puts("K1")
123
-
124
- #textDefs = resolve_recipe_texts(attrTexts)
125
- textDefs = resolve_recipe_texts(attrTexts.empty? ? :package_accessor_with_contract : attrTexts) # default is contract accessor
126
-
127
- #puts("TEXT DEFS >#{textDefs.class}< >#{textDefs}<")
128
-
129
- procBlok = Kernel.block_given? ? attrBlok : standard_accessor_recipe_block(textDefs)
130
-
131
- Potrubi::Mixin::Dynamic.dynamic_define_methods(attrTarget, attrDefs, &procBlok)
132
-
133
- $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(attrTarget: attrTarget, attrDefs: attrDefs, attrTexts: attrTexts))
134
-
135
- self
136
-
137
- ##STOPHEREACCSEXIT
138
- end
139
-
140
- def recipe_mustbes(attrTarget, attrDefs, *attrTexts, &attrBlok)
141
- eye = :'rcp_mustbes'
142
-
143
- $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_me(eye, potrubi_bootstrap_logger_fmt_who(attrTarget: attrTarget, attrDefs: attrDefs, attrTexts: attrTexts))
144
-
145
- textDefs = resolve_recipe_texts(attrTexts.empty? ? :package_mustbe : attrTexts) # default is standard mustbe
146
-
147
- procBlok = Kernel.block_given? ? attrBlok : standard_mustbe_recipe_block(textDefs)
148
-
149
- Potrubi::Mixin::Dynamic.dynamic_define_methods(attrTarget, attrDefs, &procBlok)
150
-
151
- $DEBUG_POTRUBI_BOOTSTRAP && potrubi_bootstrap_logger_mx(eye, potrubi_bootstrap_logger_fmt_who(attrTarget: attrTarget, attrDefs: attrDefs, attrTexts: attrTexts))
152
-
153
- self
154
-
155
- end
156
-
157
- end
158
-
159
- module Potrubi
160
- module Mixin
161
- module ContractRecipes
162
- end
163
- end
164
- end
165
-
166
- Potrubi::Mixin::ContractRecipes.extend(mixinContent) # Make mixin methods
167
-
168
- __END__
169
-
170
- # quick tests
171
-
172
- require '../core'
173
-
174
- $DEBUG = true
175
- $DEBUG_POTRUBI_BOOTSTRAP = true
176
-
177
- testClass = Class.new do
178
-
179
- include Potrubi::Core
180
-
181
- attrAccessors = {
182
- #jmx_user: :string,
183
- #jmx_pass: :string,
184
- #jmx_host: :string,
185
- ###jmx_port: :string,
186
- #jmx_port: :fixnum,
187
- #jmx_connection: nil,
188
- #jmx_connection: 'JMX::MBeanServerConnectionProxy',
189
- #beans_attributes: :hash,
190
- #beans_specifications: :hash,
191
- #jmx_host: ->(h) {h.is_a?(String)},
192
-
193
- #jmx_orts: {spec: 'def is_value_jmx_orts?(v); v.is_a?(String); end'},
194
-
195
- #jmx_keys: {edit: {ACCESSOR_KEYS: 'self.class.accessor_keys'},
196
- #spec: :method_accessor_is_value_and_keys}
197
-
198
- jmx_users1: {edit: {KEY_TYPE: :string, VALUE_TYPE: :jmx_user}, spec: :method_accessor_is_value_typed_collection},
199
- jmx_users2: {edit: {KEY_TYPE: :string, VALUE_TYPE: :jmx_user, VALUE_IS_NIL_RESULT: 'true', KEY_NAMES: [:a, :b, :c]}, spec: :method_accessor_is_value_typed_collection_with_keys}
200
-
201
-
202
- }
203
-
204
- attraccessorTexts = [:package_accessor_with_contract]
205
-
206
- Potrubi::Mixin::ContractRecipes.recipe_accessors(self, attrAccessors, attraccessorTexts)
207
-
208
-
209
- mustbeContracts = {
210
- what1: :string,
211
- what2: :hash,
212
- what3: 'Riemann::Feed::Feeder'
213
- }
214
-
215
- #Potrubi::Mixin::ContractRecipes.recipe_mustbes(self, mustbeContracts)
216
-
217
- end
218
-
219
- testInst = testClass.new
220
-
221
- #testInst.mustbe_jmx_host_or_croak('A string')
222
- #testInst.mustbe_jmx_host_or_croak(:symbol)
223
- #testInst.mustbe_jmx_orts_or_croak('A string')
224
- #testInst.mustbe_jmx_orts_or_croak(:symbol)
225
- __END__
226
-