lizarb 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/loops_bench.rb +35 -0
  10. data/app/dev/commands/calculator_command.rb +69 -0
  11. data/app/dev/commands/calculator_command_test.rb +58 -0
  12. data/app/dev/commands/circle_command.rb +70 -0
  13. data/app/dev/commands/circle_command_test.rb +76 -0
  14. data/app/dev/commands/narrative_method_command.rb +60 -0
  15. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  16. data/app/dev/commands/quadratic_command.rb +66 -0
  17. data/app/dev/commands/quadratic_command_test.rb +47 -0
  18. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  19. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  20. data/app/dev/generators/bench_generator.rb +2 -51
  21. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  22. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  23. data/app/dev/generators/command_generator.rb +2 -35
  24. data/app/dev/generators/record_generator.rb +46 -0
  25. data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
  26. data/app/dev_box.rb +24 -4
  27. data/app/happy_box.rb +1 -1
  28. data/app/net/databases/sqlite_db_test.rb +5 -5
  29. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  30. data/app/net/records/app_record_test.rb +8 -0
  31. data/app/net/records/post_record.rb +4 -0
  32. data/app/net/records/post_record_test.rb +8 -0
  33. data/app/net/records/user_record.rb +4 -0
  34. data/app/net/records/user_record_test.rb +8 -0
  35. data/app/net_box.rb +7 -7
  36. data/app/web/requests/api_request.rb +8 -7
  37. data/app/web/requests/assets_request.rb +12 -13
  38. data/app/web/requests/root_request.rb +6 -7
  39. data/app/web/requests/root_request_test.rb +1 -1
  40. data/app/web_box.rb +9 -1
  41. data/exe/lrb +3 -0
  42. data/lib/app.rb +19 -15
  43. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +27 -0
  44. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench/not_found_bench_test.rb} +3 -5
  45. data/lib/dev_system/dev/controllers/bench.rb +5 -7
  46. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +37 -39
  47. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command/bench_command.rb +20 -12
  49. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/command/echo_command.rb +5 -7
  51. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +8 -10
  52. data/lib/dev_system/dev/controllers/command/generate_command.rb +22 -12
  53. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  54. data/lib/dev_system/dev/controllers/command/not_found_command.rb +27 -0
  55. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +12 -0
  56. data/lib/dev_system/dev/controllers/command/terminal_command.rb +22 -0
  57. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +12 -0
  58. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -49
  59. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  60. data/lib/dev_system/dev/controllers/command/version_command.rb +4 -6
  61. data/lib/dev_system/dev/controllers/command/version_command_test.rb +8 -10
  62. data/lib/dev_system/dev/controllers/command.rb +11 -13
  63. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  64. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  65. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +35 -37
  66. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  67. data/lib/dev_system/dev/controllers/generators/app_generator.rb +122 -47
  68. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +8 -10
  69. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  75. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +12 -0
  77. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  79. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  81. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  82. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  83. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  85. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  86. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  87. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +11 -13
  88. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  89. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  91. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  92. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  93. data/lib/dev_system/dev/dev_box.rb +33 -16
  94. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  95. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  96. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  97. data/lib/dev_system/dev/panels/command_panel.rb +24 -6
  98. data/lib/dev_system/dev/panels/command_panel_test.rb +15 -17
  99. data/lib/dev_system/dev/panels/generator_panel.rb +3 -0
  100. data/lib/dev_system/dev/panels/generator_panel_test.rb +12 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  103. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  104. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  105. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  106. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  107. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  108. data/lib/happy_system/happy/happy_box.rb +6 -9
  109. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  110. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  111. data/lib/lerb.rb +106 -0
  112. data/lib/liza/base/box.rb +71 -26
  113. data/lib/liza/base/box_test.rb +7 -9
  114. data/lib/liza/base/controller.rb +19 -19
  115. data/lib/liza/base/controller_test.rb +7 -9
  116. data/lib/liza/base/panel.rb +40 -24
  117. data/lib/liza/base/panel_test.rb +10 -12
  118. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  119. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  120. data/lib/liza/meta/part.rb +12 -14
  121. data/lib/liza/meta/part_extension.rb +14 -11
  122. data/lib/liza/meta/part_test.rb +4 -6
  123. data/lib/liza/meta/system.rb +12 -14
  124. data/lib/liza/meta/system_test.rb +8 -10
  125. data/lib/liza/ruby_test.rb +7 -0
  126. data/lib/liza/ruby_tests/module_test.rb +21 -0
  127. data/lib/liza/ruby_tests/string_test.rb +59 -0
  128. data/lib/liza/test/test.rb +7 -8
  129. data/lib/liza/test/test_test.rb +168 -76
  130. data/lib/liza/test_parts/test_assertions_advanced_part.rb +125 -0
  131. data/lib/liza/test_parts/test_assertions_part.rb +81 -82
  132. data/lib/liza/test_parts/test_dsl_part.rb +44 -98
  133. data/lib/liza/test_parts/test_log_part.rb +122 -0
  134. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  135. data/lib/liza/test_parts/test_tree_part.rb +137 -0
  136. data/lib/liza/unit.rb +108 -102
  137. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  138. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  139. data/lib/liza/unit_test.rb +69 -71
  140. data/lib/liza.rb +5 -0
  141. data/lib/lizarb/ruby/module.rb +17 -0
  142. data/lib/lizarb/ruby/string.rb +10 -2
  143. data/lib/lizarb/version.rb +1 -1
  144. data/lib/lizarb.rb +24 -2
  145. data/lib/net_system/dev/net_command.rb +10 -12
  146. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  147. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  148. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  149. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  150. data/lib/net_system/net/controllers/client.rb +1 -3
  151. data/lib/net_system/net/controllers/client_test.rb +8 -10
  152. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  153. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  154. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  155. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  156. data/lib/net_system/net/controllers/database.rb +21 -23
  157. data/lib/net_system/net/controllers/database_test.rb +8 -10
  158. data/lib/net_system/net/controllers/record.rb +29 -0
  159. data/lib/net_system/net/controllers/record_test.rb +12 -0
  160. data/lib/net_system/net/net_box.rb +11 -16
  161. data/lib/net_system/net/net_box_test.rb +12 -14
  162. data/lib/net_system/net/panels/client_panel.rb +1 -3
  163. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  164. data/lib/net_system/net/panels/database_panel.rb +6 -8
  165. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  166. data/lib/web_system/dev/rack_command.rb +35 -0
  167. data/lib/web_system/dev/request_command.rb +143 -0
  168. data/lib/web_system/dev/web_command.rb +6 -39
  169. data/lib/web_system/web/controllers/rack.rb +6 -0
  170. data/lib/web_system/web/controllers/rack_test.rb +16 -0
  171. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -12
  172. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -12
  173. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -13
  174. data/lib/web_system/web/controllers/request.rb +1 -3
  175. data/lib/web_system/web/controllers/request_test.rb +11 -13
  176. data/lib/web_system/web/panels/rack_panel.rb +42 -0
  177. data/lib/web_system/web/panels/rack_panel_test.rb +12 -0
  178. data/lib/web_system/web/panels/request_panel.rb +54 -37
  179. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  180. data/lib/web_system/web/web_box.rb +16 -8
  181. data/lib/web_system/web/web_box_test.rb +11 -13
  182. data/lizarb.gemspec +2 -2
  183. metadata +76 -28
  184. data/app/dev/commands/example_command.rb +0 -57
  185. data/app/dev/commands/example_command_test.rb +0 -43
  186. data/app/dev/commands/macro_child_command.rb +0 -32
  187. data/app/dev/commands/macro_child_command_test.rb +0 -7
  188. data/app/dev/commands/macro_parent_command.rb +0 -70
  189. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  190. data/app/dev/commands/my_command.rb +0 -7
  191. data/app/dev/commands/my_command_test.rb +0 -7
  192. data/app/dev/generators/model_generator.rb +0 -46
  193. data/app/net/models/app_model_test.rb +0 -8
  194. data/app/net/models/post_model.rb +0 -4
  195. data/app/net/models/post_model_test.rb +0 -8
  196. data/app/net/models/user_model.rb +0 -4
  197. data/app/net/models/user_model_test.rb +0 -8
  198. data/app_new/.gitignore +0 -4
  199. data/app_new/Gemfile +0 -31
  200. data/app_new/Procfile +0 -3
  201. data/lib/dev_system/dev/controllers/command/dev_command.rb +0 -24
  202. data/lib/liza/test_parts/test_context_part.rb +0 -81
  203. data/lib/net_system/net/controllers/model.rb +0 -31
  204. data/lib/net_system/net/controllers/model_test.rb +0 -14
data/lib/liza/unit.rb CHANGED
@@ -1,149 +1,155 @@
1
- module Liza
2
- class Unit
1
+ class Liza::Unit
3
2
 
4
- # PARTS
3
+ # PARTS
5
4
 
6
- def self.part key, system: nil
7
- App.connect_part self, key, system
8
- end
5
+ def self.part key, system: nil
6
+ App.connect_part self, key, system
7
+ end
9
8
 
10
- # SETTINGS
9
+ def self.const_missing name
10
+ Liza.const name
11
+ rescue Liza::ConstNotFound => e
12
+ raise NameError, "uninitialized constant #{name}", caller[1..], cause: nil
13
+ end
11
14
 
12
- def self.settings
13
- @settings ||= {}
14
- end
15
+ part :unit_procedure
15
16
 
16
- def self.get key
17
- return settings[key] if settings.has_key? key
17
+ # SETTINGS
18
18
 
19
- found = nil
19
+ def self.settings
20
+ @settings ||= {}
21
+ end
20
22
 
21
- for klass in ancestors
22
- break unless klass.respond_to? :settings
23
+ def self.get key
24
+ return settings[key] if settings.has_key? key
23
25
 
24
- if klass.settings.has_key? key
25
- found = klass.settings[key]
26
+ found = nil
26
27
 
27
- break
28
- end
29
- end
28
+ for klass in ancestors
29
+ break unless klass.respond_to? :settings
30
30
 
31
- found = settings[key] = found.dup if found.is_a? Enumerable
31
+ if klass.settings.has_key? key
32
+ found = klass.settings[key]
32
33
 
33
- found
34
+ break
35
+ end
34
36
  end
35
37
 
36
- def self.set key, value
37
- settings[key] = value
38
- value
39
- end
38
+ found = settings[key] = found.dup if found.is_a? Enumerable
40
39
 
41
- def self.add list, key = nil, value
42
- if key
43
- fetch(list) { Hash.new }[key] = value
44
- else
45
- fetch(list) { Set.new } << value
46
- end
47
- end
40
+ found
41
+ end
48
42
 
49
- def self.fetch key, &block
50
- x = get key
51
- x ||= set key, instance_eval(&block)
52
- x
53
- end
43
+ def self.set key, value
44
+ settings[key] = value
45
+ value
46
+ end
54
47
 
55
- def settings
56
- @settings ||= {}
48
+ def self.add list, key = nil, value
49
+ if key
50
+ fetch(list) { Hash.new }[key] = value
51
+ else
52
+ fetch(list) { Set.new } << value
57
53
  end
54
+ end
58
55
 
59
- def get key
60
- return settings[key] if settings.has_key? key
56
+ def self.fetch key, &block
57
+ x = get key
58
+ x ||= set key, instance_eval(&block)
59
+ x
60
+ end
61
61
 
62
- self.class.get key
63
- end
62
+ def settings
63
+ @settings ||= {}
64
+ end
64
65
 
65
- def set key, value
66
- settings[key] = value
67
- end
66
+ def get key
67
+ return settings[key] if settings.has_key? key
68
68
 
69
- def add list, key = nil, value
70
- if key
71
- fetch(list) { Hash.new }[key] = value
72
- else
73
- fetch(list) { Set.new } << value
74
- end
75
- end
69
+ self.class.get key
70
+ end
71
+
72
+ def set key, value
73
+ settings[key] = value
74
+ end
76
75
 
77
- def fetch key, &block
78
- x = get key
79
- x ||= set key, eval(&block)
80
- x
76
+ def add list, key = nil, value
77
+ if key
78
+ fetch(list) { Hash.new }[key] = value
79
+ else
80
+ fetch(list) { Set.new } << value
81
81
  end
82
+ end
82
83
 
83
- # LOG
84
+ def fetch key, &block
85
+ x = get key
86
+ x ||= set key, eval(&block)
87
+ x
88
+ end
84
89
 
85
- LOG_LEVELS = {
86
- :higher => 2,
87
- :high => 1,
88
- :normal => 0,
89
- :low => -1,
90
- :lower => -2,
91
- }
90
+ # LOG
92
91
 
93
- set :log_level, :normal
94
- set :log_color, :white
92
+ LOG_LEVELS = {
93
+ :higher => 2,
94
+ :high => 1,
95
+ :normal => 0,
96
+ :low => -1,
97
+ :lower => -2,
98
+ }
95
99
 
96
- #
100
+ set :log_level, :normal
101
+ set :log_color, :white
97
102
 
98
- LOG_JUST = 40
103
+ #
99
104
 
100
- def self.log log_level = :normal, string
101
- raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
102
- return unless log_level? log_level
105
+ LOG_JUST = 40
103
106
 
104
- source = (self.is_a? Class) ? self : self.class
105
- source = source.to_s.ljust(LOG_JUST).bold.colorize(source.log_color)
107
+ def self.log log_level = :normal, string
108
+ raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
109
+ return unless log_level? log_level
106
110
 
107
- string = "#{source} #{string}"
111
+ source = (self.is_a? Class) ? self : self.class
112
+ source = source.to_s.ljust(LOG_JUST).bold.colorize(source.log_color)
108
113
 
109
- DevBox.logs.call string
110
- end
114
+ string = "#{source} #{string}"
111
115
 
112
- def self.log_level
113
- get(:log_level) || :normal
114
- end
116
+ DevBox[:log].call string
117
+ end
115
118
 
116
- def self.log_level? log_level = :normal
117
- # TODO
118
- true
119
- end
119
+ def self.log_level
120
+ get(:log_level) || :normal
121
+ end
120
122
 
121
- def self.log_color
122
- (get(:system) || self).get :log_color
123
- end
123
+ def self.log_level? log_level = :normal
124
+ # TODO
125
+ true
126
+ end
124
127
 
125
- def self.log?(log_level = :normal)= log_level? log_level
126
- def log(...)= self.class.log(...)
127
- def log_level(...)= self.class.log_level(...)
128
- def log?(...)= self.class.log?(...)
129
- def log_level?(...)= self.class.log_level?(...)
130
- def log_color(...)= self.class.log_color(...)
128
+ def self.log_color
129
+ (get(:system) || self).get :log_color
130
+ end
131
131
 
132
- # SYSTEM
132
+ def self.log?(log_level = :normal)= log_level? log_level
133
+ def log(...)= self.class.log(...)
134
+ def log_level(...)= self.class.log_level(...)
135
+ def log?(...)= self.class.log?(...)
136
+ def log_level?(...)= self.class.log_level?(...)
137
+ def log_color(...)= self.class.log_color(...)
133
138
 
134
- def self.inherited_explicitly_sets_system
139
+ # SYSTEM
135
140
 
136
- def self.inherited sub
137
- super
141
+ def self.inherited_explicitly_sets_system
138
142
 
139
- return unless sub.name.to_s.include? "::"
143
+ def self.inherited sub
144
+ super
140
145
 
141
- system = Object.const_get sub.first_namespace
146
+ return unless sub.name.to_s.include? "::"
142
147
 
143
- sub.set :system, system
144
- end
148
+ system = Object.const_get sub.first_namespace
145
149
 
150
+ sub.set :system, system
146
151
  end
147
152
 
148
153
  end
154
+
149
155
  end
@@ -0,0 +1,17 @@
1
+ class Liza::UnitProcedurePart < Liza::Part
2
+
3
+ insertion do
4
+ def self.procedure _label, &block
5
+ catch :procedure, &block
6
+ end
7
+
8
+ def self.proceed val = nil, &block
9
+ val = yield if val.nil? && block_given?
10
+ throw :procedure, val
11
+ end
12
+
13
+ def procedure(_label, &block)= self.class.procedure _label, &block
14
+ def proceed(...)= self.class.proceed(...)
15
+ end
16
+
17
+ end
@@ -0,0 +1,65 @@
1
+ class Liza::UnitProcedurePartTest < Liza::UnitTest
2
+
3
+ test :procedure_scopes_and_returns do
4
+ b = nil
5
+
6
+ w =
7
+ procedure "creates a new scope" do
8
+ @a = 1
9
+ b = 2
10
+ c = 3
11
+ assert true
12
+
13
+ proceed if true
14
+ raise "did not get here"
15
+ end
16
+
17
+ assert assertions > 0
18
+ assert w.nil?
19
+
20
+ x =
21
+ procedure "asserts old scope is not accessible" do
22
+ assert instance_variables.include? :@a
23
+ assert local_variables.include? :b
24
+ refute local_variables.include? :c
25
+
26
+ assert @a == 1
27
+ assert b == 2
28
+
29
+ proceed 100 if true
30
+ raise "did not get here"
31
+ end
32
+
33
+ assert x == 100
34
+
35
+ y =
36
+ procedure "asserts proceed calls can be lazy" do
37
+ proceed { "slow operation"; 200 } if true
38
+ raise "did not get here"
39
+ end
40
+
41
+ assert y == 200
42
+ end
43
+
44
+ test :procedure_rescue_and_ensure do
45
+ procedure "assert ensure works" do
46
+ @a = 1
47
+ ensure
48
+ @a = 2
49
+ end
50
+
51
+ assert @a == 2
52
+
53
+ procedure "assert rescue works" do
54
+ @a = [1]
55
+ raise "a runtime error!"
56
+ rescue RuntimeError
57
+ @a << 2
58
+ ensure
59
+ @a << 3
60
+ end
61
+
62
+ assert @a == [1, 2, 3]
63
+ end
64
+
65
+ end
@@ -1,79 +1,77 @@
1
- module Liza
2
- class UnitTest < Test
3
- test :subject_class do
4
- assert subject_class == Liza::Unit
5
- end
1
+ class Liza::UnitTest < Liza::Test
2
+ test :subject_class do
3
+ assert subject_class == Liza::Unit
4
+ end
5
+
6
+ test :settings do
7
+ assert subject_class.get(:log_level) == :normal
8
+ assert subject_class.get(:log_color) == :white
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :white
11
+
12
+ assert subject_class.settings == {log_level: :normal, log_color: :white}
13
+ end
14
+
15
+ test :settings_inheritance do
16
+ class_a = Class.new(subject_class) do
17
+ set :number, 1
18
+
19
+ add :default, 10
20
+ add :default, 20
6
21
 
7
- test :settings do
8
- assert subject_class.get(:log_level) == :normal
9
- assert subject_class.get(:log_color) == :white
10
- assert subject_class.log_level == :normal
11
- assert subject_class.log_color == :white
22
+ set :array, []
23
+ add :array, 10
24
+ add :array, 20
12
25
 
13
- assert subject_class.settings == {log_level: :normal, log_color: :white}
26
+ add :hash, :a, 10
27
+ add :hash, :b, 20
14
28
  end
15
29
 
16
- test :settings_inheritance do
17
- class_a = Class.new(subject_class) do
18
- set :number, 1
19
-
20
- add :default, 10
21
- add :default, 20
22
-
23
- set :array, []
24
- add :array, 10
25
- add :array, 20
26
-
27
- add :hash, :a, 10
28
- add :hash, :b, 20
29
- end
30
-
31
- assert class_a.settings == {
32
- number: 1,
33
- default: Set[10, 20],
34
- array: [10, 20],
35
- hash: {a: 10, b: 20}
36
- }
37
-
38
- assert class_a.get(:default) == Set[10, 20]
39
- assert class_a.get(:array) == [10, 20]
40
- assert class_a.get(:hash) == {a: 10, b: 20}
41
-
42
- class_b = Class.new(class_a) do
43
- set :string, "a"
44
-
45
- add :default, 30
46
- add :default, 40
47
-
48
- add :array, 30
49
- add :array, 40
50
-
51
- add :hash, :c, 30
52
- add :hash, :d, 40
53
- end
54
-
55
- assert class_a.settings == {
56
- number: 1,
57
- default: Set[10, 20],
58
- array: [10, 20],
59
- hash: {a: 10, b: 20}
60
- }
61
-
62
- assert class_a.get(:default) == Set[10, 20]
63
- assert class_a.get(:array) == [10, 20]
64
- assert class_a.get(:hash) == {a: 10, b: 20}
65
-
66
- assert class_b.settings == {
67
- string: "a",
68
- default: Set[10, 20, 30, 40],
69
- array: [10, 20, 30, 40],
70
- hash: {a: 10, b: 20, c: 30, d: 40}
71
- }
72
-
73
- assert class_b.get(:default) == Set[10, 20, 30, 40]
74
- assert class_b.get(:array) == [10, 20, 30, 40]
75
- assert class_b.get(:hash) == {a: 10, b: 20, c: 30, d: 40}
30
+ assert class_a.settings == {
31
+ number: 1,
32
+ default: Set[10, 20],
33
+ array: [10, 20],
34
+ hash: {a: 10, b: 20}
35
+ }
36
+
37
+ assert class_a.get(:default) == Set[10, 20]
38
+ assert class_a.get(:array) == [10, 20]
39
+ assert class_a.get(:hash) == {a: 10, b: 20}
40
+
41
+ class_b = Class.new(class_a) do
42
+ set :string, "a"
43
+
44
+ add :default, 30
45
+ add :default, 40
46
+
47
+ add :array, 30
48
+ add :array, 40
49
+
50
+ add :hash, :c, 30
51
+ add :hash, :d, 40
76
52
  end
77
53
 
54
+ assert class_a.settings == {
55
+ number: 1,
56
+ default: Set[10, 20],
57
+ array: [10, 20],
58
+ hash: {a: 10, b: 20}
59
+ }
60
+
61
+ assert class_a.get(:default) == Set[10, 20]
62
+ assert class_a.get(:array) == [10, 20]
63
+ assert class_a.get(:hash) == {a: 10, b: 20}
64
+
65
+ assert class_b.settings == {
66
+ string: "a",
67
+ default: Set[10, 20, 30, 40],
68
+ array: [10, 20, 30, 40],
69
+ hash: {a: 10, b: 20, c: 30, d: 40}
70
+ }
71
+
72
+ assert class_b.get(:default) == Set[10, 20, 30, 40]
73
+ assert class_b.get(:array) == [10, 20, 30, 40]
74
+ assert class_b.get(:hash) == {a: 10, b: 20, c: 30, d: 40}
78
75
  end
76
+
79
77
  end
data/lib/liza.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Liza
4
4
  class Error < StandardError; end
5
+ class ConstNotFound < Error; end
5
6
 
6
7
  #
7
8
 
@@ -27,6 +28,8 @@ module Liza
27
28
  return k if k
28
29
 
29
30
  nil
31
+ rescue NameError
32
+ raise ConstNotFound, name
30
33
  end
31
34
 
32
35
  # Checks each system, then Liza for Liza::Unit classes
@@ -46,6 +49,8 @@ module Liza
46
49
  end
47
50
 
48
51
  def const_check_systems name
52
+ App.systems.frozen? or return nil
53
+
49
54
  for k in App.systems.values.reverse
50
55
  next if not k.const_defined? name.to_sym
51
56
  kk = k.const(name) if k.constants.include? name
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Module
4
+
5
+ # /path/to/liza.rb
6
+ def source_location
7
+ Object.const_source_location name
8
+ end
9
+
10
+ # /path/to/liza
11
+ def source_location_radical
12
+ source_location[0][0..-4]
13
+ rescue
14
+ nil
15
+ end
16
+
17
+ end
@@ -3,10 +3,18 @@
3
3
  class String
4
4
  alias lpartition partition
5
5
 
6
- def camelize
7
- split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
6
+ def camelcase
7
+ split("_").map { |s| "#{s[0].to_s.upcase}#{s[1..-1]}" }.join("")
8
8
  end
9
9
 
10
+ alias camelize camelcase
11
+
12
+ def snakecase
13
+ gsub(/[A-Z\s-]/) { |s, t| "_#{s}" }[1..-1].to_s.downcase
14
+ end
15
+
16
+ alias snakefy snakecase
17
+
10
18
  def rjust_blanks length
11
19
  rjust length, " "
12
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lizarb
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
data/lib/lizarb.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "colorize"
4
+ require "json"
4
5
  require "pathname"
5
6
  require "zeitwerk"
7
+ require "lerb"
6
8
 
7
9
  require_relative "lizarb/version"
8
10
 
@@ -11,7 +13,8 @@ module Lizarb
11
13
 
12
14
  #
13
15
 
14
- GEM_DIR = Gem::Specification.find_by_name("lizarb").gem_dir
16
+ SPEC = Gem::Specification.find_by_name("lizarb")
17
+ GEM_DIR = SPEC.gem_dir
15
18
  CUR_DIR = Dir.pwd
16
19
 
17
20
  IS_APP_DIR = File.file? "#{CUR_DIR}/app.rb"
@@ -36,7 +39,10 @@ module Lizarb
36
39
 
37
40
  require "#{APP_DIR}/app"
38
41
 
39
- VERSION
42
+ versions = {ruby: RUBY_VERSION, bundler: Bundler::VERSION, zeitwerk: Zeitwerk::VERSION, lizarb: VERSION}
43
+ bugs = SPEC.metadata["bug_tracker_uri"]
44
+ puts versions.to_s.green
45
+ puts "Report bugs at #{bugs}"
40
46
  end
41
47
 
42
48
  # called from "#{APP_DIR}/app"
@@ -65,4 +71,20 @@ module Lizarb
65
71
  : "#{GEM_DIR}/exe/Gemfile"
66
72
  end
67
73
 
74
+ # threads
75
+
76
+ def thread_object_id
77
+ Thread.current.object_id
78
+ end
79
+
80
+ @thread_ids = {thread_object_id => 0}
81
+ @thread_ids_mutex = Mutex.new
82
+
83
+ def thread_id
84
+ @thread_ids[thread_object_id] ||=
85
+ @thread_ids_mutex.synchronize do
86
+ @thread_ids.count
87
+ end
88
+ end
89
+
68
90
  end
@@ -1,14 +1,13 @@
1
- class NetSystem
2
- class NetCommand < Liza::Command
1
+ class NetSystem::NetCommand < Liza::Command
3
2
 
4
- def self.call args
5
- log :higher, "Called #{self} with args #{args}"
3
+ def self.call args
4
+ log :higher, "Called #{self} with args #{args}"
6
5
 
7
- ruby_time = Time.now
8
- redis_time = ::NetBox.databases.redis.now
9
- sqlite_time = ::NetBox.databases.sqlite.now
10
- # redis_time = ::RedisDb.current.now
11
- # sqlite_time = ::SqliteDb.current.now
6
+ ruby_time = Time.now
7
+ redis_time = ::NetBox.databases.redis.now
8
+ sqlite_time = ::NetBox.databases.sqlite.now
9
+ # redis_time = ::RedisDb.current.now
10
+ # sqlite_time = ::SqliteDb.current.now
12
11
 
13
12
  puts <<-OUTPUT.bold
14
13
 
@@ -17,8 +16,7 @@ class NetSystem
17
16
  Time for Sqlite: #{sqlite_time.to_s.light_red}
18
17
 
19
18
  OUTPUT
20
- Liza::DevCommand.call []
21
- end
22
-
19
+ Liza::DevCommand.call []
23
20
  end
21
+
24
22
  end