lizarb 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -13
  3. data/Rakefile +38 -0
  4. data/app/dev_box.rb +26 -4
  5. data/app/happy_box.rb +2 -2
  6. data/app/net/databases/sqlite_db_test.rb +5 -5
  7. data/app/net/records/app_record_test.rb +1 -1
  8. data/app/net/records/post_record_test.rb +1 -1
  9. data/app/net/records/user_record_test.rb +1 -1
  10. data/app/net_box.rb +9 -9
  11. data/app/web_box.rb +4 -4
  12. data/app.rb +6 -7
  13. data/{exe/Gemfile → app_global.gemfile.rb} +2 -0
  14. data/app_global.gemfile.rb.lock +19 -0
  15. data/app_global.rb +4 -0
  16. data/{app → app_new}/dev/benches/loops_bench.rb +3 -2
  17. data/{app/dev/generators/bench_generator_test.rb → app_new/dev/benches/loops_bench_test.rb} +2 -2
  18. data/app_new/dev/benches/objects_bench.rb +83 -0
  19. data/{app/dev/generators/record_generator_test.rb → app_new/dev/benches/objects_bench_test.rb} +2 -2
  20. data/app_new/dev/benches/sorted_bench.rb +54 -0
  21. data/app_new/dev/benches/sorted_bench_test.rb +12 -0
  22. data/app_new/dev/benches/variables_bench.rb +55 -0
  23. data/{app/dev/generators/command_generator_test.rb → app_new/dev/benches/variables_bench_test.rb} +2 -2
  24. data/{app → app_new}/dev/commands/calculator_command.rb +1 -1
  25. data/{app → app_new}/dev/commands/circle_command.rb +1 -1
  26. data/{app → app_new}/dev/commands/narrative_method_command.rb +5 -7
  27. data/{app → app_new}/dev/commands/quadratic_command.rb +1 -1
  28. data/app_new/dev_box.rb +14 -0
  29. data/app_new.rb +15 -0
  30. data/exe/lizarb +9 -1
  31. data/lib/app.rb +27 -95
  32. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +23 -18
  33. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +9 -11
  34. data/lib/dev_system/dev/controllers/bench.rb +1 -9
  35. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  36. data/lib/dev_system/dev/controllers/command/bench_command.rb +19 -22
  37. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  38. data/lib/dev_system/dev/controllers/command/generate_command.rb +5 -31
  39. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  40. data/lib/dev_system/dev/controllers/command/new_command.rb +9 -0
  41. data/lib/dev_system/dev/controllers/command/new_command_test.rb +7 -0
  42. data/lib/dev_system/dev/controllers/command/not_found_command.rb +37 -18
  43. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +8 -10
  44. data/lib/dev_system/dev/controllers/command/terminal_command.rb +12 -14
  45. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +8 -10
  46. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -53
  47. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command.rb +9 -15
  49. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  51. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +33 -37
  52. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  53. data/{app/dev/generators/bench_generator/bench.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller.rb.erb} +1 -2
  54. data/{app/dev/generators/bench_generator/bench_test.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller_test.rb.erb} +2 -2
  55. data/lib/dev_system/dev/controllers/generators/bench_generator.rb +12 -0
  56. data/lib/dev_system/dev/controllers/generators/bench_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/command_generator/controller.rb.erb +41 -0
  58. data/{app/dev/generators/command_generator/command_test.rb.erb → lib/dev_system/dev/controllers/generators/command_generator/controller_test.rb.erb} +2 -2
  59. data/lib/dev_system/dev/controllers/generators/command_generator.rb +19 -0
  60. data/lib/dev_system/dev/controllers/generators/command_generator_test.rb +12 -0
  61. data/lib/dev_system/dev/controllers/generators/controller_generator.rb +97 -0
  62. data/lib/dev_system/dev/controllers/generators/controller_generator_test.rb +12 -0
  63. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +1 -1
  64. data/lib/dev_system/dev/controllers/generators/new_generator.rb +117 -0
  65. data/lib/dev_system/dev/controllers/generators/new_generator_test.rb +12 -0
  66. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -17
  67. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +8 -10
  68. data/{app/dev → lib/dev_system/dev/controllers}/generators/record_generator.rb +1 -1
  69. data/lib/dev_system/dev/controllers/generators/record_generator_test.rb +12 -0
  70. data/{app/dev → lib/dev_system/dev/controllers}/generators/request_generator.rb +2 -2
  71. data/lib/dev_system/dev/controllers/generators/request_generator_test.rb +12 -0
  72. data/lib/dev_system/dev/controllers/log.rb +3 -0
  73. data/{app/dev/generators/request_generator_test.rb → lib/dev_system/dev/controllers/log_test.rb} +2 -2
  74. data/lib/dev_system/dev/controllers/shell.rb +22 -0
  75. data/lib/dev_system/dev/controllers/shell_test.rb +25 -0
  76. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +15 -11
  77. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  78. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  79. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  80. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  81. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  82. data/lib/dev_system/dev/dev_box.rb +27 -16
  83. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  84. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  85. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  86. data/lib/dev_system/dev/panels/command_panel.rb +59 -18
  87. data/lib/dev_system/dev/panels/command_panel_test.rb +43 -20
  88. data/lib/dev_system/dev/panels/generator_panel.rb +73 -0
  89. data/lib/dev_system/dev/panels/generator_panel_test.rb +46 -0
  90. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  91. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  92. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  93. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  94. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  95. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  96. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  97. data/lib/happy_system/happy/happy_box.rb +5 -9
  98. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  99. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  100. data/lib/lerb.rb +95 -49
  101. data/lib/liza/base/box.rb +76 -26
  102. data/lib/liza/base/box_test.rb +7 -9
  103. data/lib/liza/base/controller.rb +19 -21
  104. data/lib/liza/base/controller_test.rb +7 -9
  105. data/lib/liza/base/panel.rb +40 -27
  106. data/lib/liza/base/panel_test.rb +36 -12
  107. data/lib/liza/base_parts/controller_renderer_part.rb +1 -1
  108. data/lib/liza/meta/part.rb +12 -14
  109. data/lib/liza/meta/part_extension.rb +14 -16
  110. data/lib/liza/meta/part_test.rb +4 -6
  111. data/lib/liza/meta/system.rb +12 -14
  112. data/lib/liza/meta/system_test.rb +8 -10
  113. data/lib/liza/ruby_test.rb +4 -6
  114. data/lib/liza/ruby_tests/module_test.rb +3 -3
  115. data/lib/liza/test/test.rb +7 -10
  116. data/lib/liza/test/test_test.rb +160 -157
  117. data/lib/liza/test_parts/test_assertions_advanced_part.rb +102 -104
  118. data/lib/liza/test_parts/test_assertions_part.rb +81 -83
  119. data/lib/liza/test_parts/test_dsl_part.rb +47 -49
  120. data/lib/liza/test_parts/test_log_part.rb +88 -90
  121. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  122. data/lib/liza/test_parts/test_tree_part.rb +73 -120
  123. data/lib/liza/unit.rb +105 -107
  124. data/lib/liza/unit_parts/unit_procedure_part_test.rb +9 -9
  125. data/lib/liza/unit_parts/unit_settings_part.rb +76 -0
  126. data/lib/liza/unit_parts/unit_settings_part_test.rb +3 -0
  127. data/lib/liza/unit_test.rb +80 -71
  128. data/lib/liza.rb +10 -1
  129. data/lib/lizarb/ruby/module.rb +1 -1
  130. data/lib/lizarb/version.rb +1 -1
  131. data/lib/lizarb.rb +247 -23
  132. data/lib/net_system/dev/net_command.rb +15 -17
  133. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  134. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  135. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  136. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  137. data/lib/net_system/net/controllers/client.rb +1 -3
  138. data/lib/net_system/net/controllers/client_test.rb +8 -10
  139. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  140. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  141. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  142. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  143. data/lib/net_system/net/controllers/database.rb +21 -23
  144. data/lib/net_system/net/controllers/database_test.rb +8 -10
  145. data/lib/net_system/net/controllers/record.rb +21 -23
  146. data/lib/net_system/net/controllers/record_test.rb +8 -10
  147. data/lib/net_system/net/net_box.rb +9 -16
  148. data/lib/net_system/net/net_box_test.rb +12 -14
  149. data/lib/net_system/net/panels/client_panel.rb +1 -3
  150. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  151. data/lib/net_system/net/panels/database_panel.rb +6 -8
  152. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  153. data/lib/web_system/dev/rack_command.rb +20 -18
  154. data/lib/web_system/dev/request_command.rb +8 -22
  155. data/lib/web_system/dev/web_command.rb +6 -8
  156. data/lib/web_system/web/controllers/rack.rb +4 -6
  157. data/lib/web_system/web/controllers/rack_test.rb +11 -13
  158. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -11
  159. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -11
  160. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -12
  161. data/lib/web_system/web/controllers/request.rb +1 -3
  162. data/lib/web_system/web/controllers/request_test.rb +11 -13
  163. data/lib/web_system/web/panels/rack_panel.rb +37 -39
  164. data/lib/web_system/web/panels/rack_panel_test.rb +8 -10
  165. data/lib/web_system/web/panels/request_panel.rb +53 -57
  166. data/lib/web_system/web/panels/request_panel_test.rb +1 -1
  167. data/lib/web_system/web/web_box.rb +12 -18
  168. data/lib/web_system/web/web_box_test.rb +11 -13
  169. data/lizarb.gemspec +1 -1
  170. metadata +54 -44
  171. data/.ruby-version +0 -1
  172. data/app/dev/benches/app_bench.rb +0 -5
  173. data/app/dev/benches/app_bench_test.rb +0 -7
  174. data/app/dev/benches/loops_bench_test.rb +0 -11
  175. data/app/dev/commands/app_command.rb +0 -5
  176. data/app/dev/commands/app_command_test.rb +0 -7
  177. data/app/dev/commands/new_command.rb +0 -9
  178. data/app/dev/commands/new_command_test.rb +0 -7
  179. data/app/dev/generators/bench_generator.rb +0 -18
  180. data/app/dev/generators/command_generator/command.rb.erb +0 -26
  181. data/app/dev/generators/command_generator.rb +0 -18
  182. data/app_new/.gitignore +0 -4
  183. data/app_new/Gemfile +0 -31
  184. data/app_new/Procfile +0 -3
  185. data/exe/Gemfile.lock +0 -13
  186. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +0 -60
  187. data/lib/dev_system/dev/controllers/command/echo_command.rb +0 -11
  188. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +0 -14
  189. data/lib/dev_system/dev/controllers/command/version_command.rb +0 -9
  190. data/lib/dev_system/dev/controllers/command/version_command_test.rb +0 -14
  191. data/lib/dev_system/dev/controllers/generators/app_generator.rb +0 -96
  192. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +0 -14
  193. /data/{app → app_new}/dev/commands/calculator_command_test.rb +0 -0
  194. /data/{app → app_new}/dev/commands/circle_command_test.rb +0 -0
  195. /data/{app → app_new}/dev/commands/narrative_method_command_test.rb +0 -0
  196. /data/{app → app_new}/dev/commands/quadratic_command_test.rb +0 -0
@@ -1,79 +1,88 @@
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
6
14
 
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
15
+ test :settings_inheritance do
16
+ class_a = Class.new(subject_class) do
17
+ set :number, 1
12
18
 
13
- assert subject_class.settings == {log_level: :normal, log_color: :white}
19
+ add :default, 10
20
+ add :default, 20
21
+
22
+ set :array, []
23
+ add :array, 10
24
+ add :array, 20
25
+
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}
75
+ end
76
+
77
+ test :build_log_sidebar_for do
78
+ assert_equality "DevSystem::Command:call ", build_log_sidebar_for(DevSystem::Command, "call", ":", panel_key: nil)
79
+ assert_equality "DevSystem::TestCommand#call ", build_log_sidebar_for(DevSystem::TestCommand, "call", "#", panel_key: nil)
80
+ assert_equality "DevBox[:command].call ", build_log_sidebar_for(DevBox, "call", ".", panel_key: :command)
81
+ end
82
+
83
+ def build_log_sidebar_for source, method_key, method_sep, panel_key: nil
84
+ s = subject_class.build_log_sidebar_for source, method_key, method_sep, panel_key: panel_key
85
+ s.uncolorize
78
86
  end
87
+
79
88
  end
data/lib/liza.rb CHANGED
@@ -14,6 +14,10 @@ module Liza
14
14
 
15
15
  #
16
16
 
17
+ def [] name
18
+ const name
19
+ end
20
+
17
21
  # Checks Object, each system, then Liza for Liza::Unit classes
18
22
  def const name
19
23
  name = name.to_s.camelize.to_sym
@@ -29,7 +33,12 @@ module Liza
29
33
 
30
34
  nil
31
35
  rescue NameError
32
- raise ConstNotFound, name
36
+ log "Liza const #{name} not found!"
37
+ if Lizarb.ruby_supports_raise_cause?
38
+ raise ConstNotFound, name, cause: nil
39
+ else
40
+ raise ConstNotFound, name, []
41
+ end
33
42
  end
34
43
 
35
44
  # Checks each system, then Liza for Liza::Unit classes
@@ -4,7 +4,7 @@ class Module
4
4
 
5
5
  # /path/to/liza.rb
6
6
  def source_location
7
- Object.const_source_location name
7
+ Array Object.const_source_location name
8
8
  end
9
9
 
10
10
  # /path/to/liza
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lizarb
4
- VERSION = "1.0.2"
4
+ VERSION = "1.0.4"
5
5
  end
data/lib/lizarb.rb CHANGED
@@ -3,13 +3,16 @@
3
3
  require "colorize"
4
4
  require "json"
5
5
  require "pathname"
6
- require "zeitwerk"
6
+ require "fileutils"
7
7
  require "lerb"
8
8
 
9
9
  require_relative "lizarb/version"
10
10
 
11
+ $APP ||= "app"
12
+
11
13
  module Lizarb
12
14
  class Error < StandardError; end
15
+ class ModeNotFound < Error; end
13
16
 
14
17
  #
15
18
 
@@ -19,9 +22,12 @@ module Lizarb
19
22
 
20
23
  IS_APP_DIR = File.file? "#{CUR_DIR}/app.rb"
21
24
  IS_LIZ_DIR = File.file? "#{CUR_DIR}/lib/lizarb.rb"
25
+ IS_GEM_DIR = File.file? "#{CUR_DIR}/lizarb.gemspec"
22
26
 
23
27
  APP_DIR = IS_APP_DIR ? CUR_DIR : GEM_DIR
24
28
 
29
+ $APP = "app_global" if not IS_APP_DIR
30
+
25
31
  #
26
32
 
27
33
  module_function
@@ -30,48 +36,266 @@ module Lizarb
30
36
  puts s.bold
31
37
  end
32
38
 
39
+ def self.logv s
40
+ log s if $VERBOSE
41
+ end
42
+
43
+ # Returns Lizarb::VERSION as a Gem::Version
44
+ def version
45
+ @version ||= Gem::Version.new VERSION
46
+ end
47
+
48
+ # Returns RUBY_VERSION as a Gem::Version
49
+ def ruby_version
50
+ @ruby_version ||= Gem::Version.new RUBY_VERSION
51
+ end
52
+
53
+ def ruby_supports_raise_cause?
54
+ RUBY_ENGINE != "jruby"
55
+ end
56
+
57
+ def self.load_all
58
+ Zeitwerk::Loader.eager_load_all
59
+ end
60
+
33
61
  # called from exe/lizarb
34
- def call
62
+ def setup
63
+ lookup_and_load_core_ext
64
+ lookup_and_set_gemfile
65
+ end
66
+
67
+ # called from exe/lizarb
68
+ def app &block
35
69
  require "app"
70
+ if block_given?
71
+ App.class_exec(&block)
72
+ else
73
+ lookup_and_require_app
74
+ end
75
+ end
36
76
 
37
- setup_core_ext
38
- setup_gemfile
77
+ # called from exe/lizarb
78
+ def call
79
+ lookup_and_set_mode
80
+ lookup_and_require_dependencies
81
+ lookup_and_load_settings
82
+ require_liza_and_bundle_systems
83
+ end
39
84
 
40
- require "#{APP_DIR}/app"
85
+ # called from exe/lizarb
86
+ def exit verbose: $VERBOSE
87
+ exit_messages if verbose
88
+ super 0
89
+ end
41
90
 
42
- versions = {ruby: RUBY_VERSION, bundler: Bundler::VERSION, zeitwerk: Zeitwerk::VERSION, lizarb: VERSION}
91
+ def exit_messages
92
+ versions = {
93
+ ruby: RUBY_VERSION,
94
+ bundler: Bundler::VERSION,
95
+ zeitwerk: Zeitwerk::VERSION,
96
+ lizarb: VERSION,
97
+ app: $APP,
98
+ mode: $MODE
99
+ }
43
100
  bugs = SPEC.metadata["bug_tracker_uri"]
44
101
  puts versions.to_s.green
45
102
  puts "Report bugs at #{bugs}"
103
+ puts "Fork us on Github at #{bugs}/fork"
46
104
  end
47
105
 
48
- # called from "#{APP_DIR}/app"
49
- def bundle
50
- require "bundler/setup"
51
- Bundler.require :default
106
+ # setup phase
107
+
108
+ def lookup_and_load_core_ext
109
+ files =
110
+ if IS_GEM_DIR
111
+ Dir["#{CUR_DIR}/lib/lizarb/ruby/*.rb"]
112
+ else
113
+ Dir["#{GEM_DIR}/lib/lizarb/ruby/*.rb"] + Dir["#{CUR_DIR}/lib/lizarb/ruby/*.rb"]
114
+ end
115
+
116
+ files.each do |file_name|
117
+ log "#{self} loading #{file_name}" if $VERBOSE
118
+ load file_name
119
+ end
120
+ end
121
+
122
+ def lookup_and_set_gemfile
123
+ gemfile = nil
52
124
 
53
- bundle_liza
125
+ finder = \
126
+ proc do |file_name|
127
+ log "#{self}.#{__method__} #{file_name}" if $VERBOSE
128
+ if File.file? file_name
129
+ file_name
130
+ else
131
+ false
132
+ end
133
+ end
134
+
135
+ gemfile ||= finder.call "#{CUR_DIR}/#{$APP}.gemfile.rb"
136
+ gemfile ||= finder.call "#{GEM_DIR}/#{$APP}.gemfile.rb" unless IS_GEM_DIR
137
+ gemfile ||= finder.call "#{CUR_DIR}/Gemfile"
138
+ gemfile ||= finder.call "#{GEM_DIR}/app_global.gemfile.rb"
54
139
 
55
- check_mode!
140
+ log "#{self} setting BUNDLE_GEMFILE to #{gemfile}" if $VERBOSE
141
+ ENV["BUNDLE_GEMFILE"] = gemfile
56
142
  end
57
143
 
58
- # setup
144
+ # app phase
59
145
 
60
- def setup_core_ext
61
- pattern =
62
- IS_LIZ_DIR ? "lib/lizarb/ruby/*.rb"
63
- : "#{GEM_DIR}/lib/lizarb/ruby/*.rb"
146
+ def lookup_and_require_app
147
+ finder = \
148
+ proc do |lib_name, file_name|
149
+ log "#{self} checking if #{file_name} exists" if $VERBOSE
150
+ if File.file? "#{file_name}"
151
+ require lib_name
152
+ true
153
+ else
154
+ false
155
+ end
156
+ end
64
157
 
65
- Dir[pattern].each &method(:load)
158
+ return if finder.call "#{CUR_DIR}/#{$APP}", "#{CUR_DIR}/#{$APP}.rb"
159
+ return if finder.call "#{GEM_DIR}/#{$APP}", "#{GEM_DIR}/#{$APP}.rb"
160
+
161
+ raise Error, "Could not find #{$APP}.rb in #{CUR_DIR} or #{GEM_DIR}"
66
162
  end
67
163
 
68
- def setup_gemfile
69
- ENV["BUNDLE_GEMFILE"] =
70
- IS_APP_DIR ? "#{CUR_DIR}/Gemfile"
71
- : "#{GEM_DIR}/exe/Gemfile"
164
+ # call phase
165
+
166
+ def lookup_and_set_mode
167
+ raise ModeNotFound, "App #{$APP} has no modes" if App.modes.empty?
168
+
169
+ mode = ENV["MODE"]
170
+ mode ||= App.modes.first
171
+ mode = mode.to_sym
172
+
173
+ raise ModeNotFound, "MODE `#{mode}` is not included in #{App.modes}" unless App.modes.include? mode
174
+
175
+ log "#{self}.#{__method__} #{mode.inspect}" if $VERBOSE
176
+ $MODE = mode
177
+ end
178
+
179
+ def lookup_and_require_dependencies
180
+ require "bundler/setup"
181
+ Bundler.require :default, *App.systems.keys
182
+ end
183
+
184
+ def lookup_and_load_settings
185
+ files = ["#{$APP}.#{$MODE}.env", "#{$APP}.env"]
186
+ require "dotenv"
187
+ Dotenv.load(*files)
188
+ end
189
+
190
+ def require_liza_and_bundle_systems
191
+ require "zeitwerk"
192
+ require "liza"
193
+
194
+ # App.loaders[0] first loads Liza, then each System class
195
+ App.loaders << loader = Zeitwerk::Loader.new
196
+ loader.tag = Liza.to_s
197
+
198
+ # collapse Liza paths
199
+
200
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
201
+ loader.collapse "#{Liza.source_location_radical}/**/*"
202
+ loader.push_dir "#{Liza.source_location_radical}", namespace: Liza
203
+
204
+ # loader setup
205
+
206
+ loader.enable_reloading
207
+ loader.setup
208
+
209
+ # load each System class
210
+
211
+ App.systems.keys.each do |k|
212
+ key = "#{k}_system"
213
+
214
+ App.require_system key
215
+ klass = Object.const_get key.camelize
216
+
217
+ App.systems[k] = klass
218
+ end
219
+
220
+ # App.loaders[1] first loads each System, then the App
221
+ App.loaders << loader = Zeitwerk::Loader.new
222
+
223
+ # collapse each System paths
224
+
225
+ App.systems.each do |k, klass|
226
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
227
+ loader.collapse "#{klass.source_location_radical}/**/*"
228
+ loader.push_dir "#{klass.source_location_radical}", namespace: klass
229
+ end
230
+
231
+ # cherrypick App paths
232
+
233
+ app_dir = "#{APP_DIR}/#{$APP}"
234
+ logv "Lizarb app loader #{app_dir}".on_cyan
235
+ list = Dir["#{app_dir}/*"].to_set
236
+ logv "Lizarb app loader lists #{list.count} entries to review".on_cyan
237
+
238
+ if list.empty?
239
+ logv "no #{app_dir} found".red
240
+ else
241
+ logv "Lizarb app loader found #{app_dir}\t\tCollapsing #{app_dir}/*".on_cyan
242
+
243
+ to_collapse = []
244
+
245
+ App.systems.each do |k, klass|
246
+ box_dir = "#{app_dir}/#{k}"
247
+ box_file = "#{box_dir}_box.rb"
248
+
249
+ if !list.include? box_file
250
+ logv "Lizarb app loader missd #{box_file}".on_light_black
251
+ else
252
+ logv "Lizarb app loader found #{box_file}\t\tto_collapse!".on_cyan
253
+ to_collapse << box_file
254
+
255
+ if !list.include? box_dir
256
+ logv "Lizarb app loader missd #{box_dir}".on_light_black
257
+ else
258
+ logv "Lizarb app loader found #{box_dir}\t\tto_collapse!".on_cyan
259
+ to_collapse << box_dir
260
+ end
261
+ end
262
+ end
263
+
264
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
265
+ to_ignore = list - to_collapse
266
+ to_ignore.each do |file|
267
+ logv "Lizarb app loader missd #{file}\t\tSkipping this one".on_light_black
268
+ loader.ignore file
269
+ end
270
+
271
+ to_collapse.each do |path|
272
+ logv "Lizarb app loader collapsing #{path}".on_cyan
273
+ if path.end_with? ".rb"
274
+ loader.collapse path
275
+ else
276
+ loader.collapse "#{path}/**/*"
277
+ end
278
+ end
279
+ loader.collapse "#{app_dir}/*"
280
+
281
+ loader.push_dir app_dir, namespace: Object
282
+ end
283
+
284
+ # loader setup
285
+
286
+ loader.enable_reloading
287
+ loader.setup
288
+
289
+ # App connects to systems
290
+
291
+ App.systems.each do |k, klass|
292
+ App.connect_system k, klass
293
+ end
294
+
295
+ App.systems.freeze
72
296
  end
73
297
 
74
- # threads
298
+ # thread management
75
299
 
76
300
  def thread_object_id
77
301
  Thread.current.object_id
@@ -1,24 +1,22 @@
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 "args = #{args.inspect}"
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[:database].redis.new.now
8
+ sqlite_time = NetBox[:database].sqlite.new.now
9
+ # redis_time = ::RedisDb.current.now
10
+ # sqlite_time = ::SqliteDb.current.now
12
11
 
13
- puts <<-OUTPUT.bold
14
12
 
15
- Time for Ruby: #{ruby_time.to_s.light_red}
16
- Time for Redis: #{redis_time.to_s.light_red}
17
- Time for Sqlite: #{sqlite_time.to_s.light_red}
18
-
19
- OUTPUT
20
- Liza::DevCommand.call []
21
- end
13
+ log "Time for Ruby: #{_red ruby_time}".bold
14
+ log "Time for Redis: #{_red redis_time}".bold
15
+ log "Time for Sqlite: #{_red sqlite_time}".bold
16
+ end
22
17
 
18
+ def self._red s
19
+ s.to_s.light_red
23
20
  end
21
+
24
22
  end
@@ -1,28 +1,26 @@
1
- class NetSystem
2
- class RedisClient < Client
1
+ class NetSystem::RedisClient < NetSystem::Client
3
2
 
4
- # https://redis.io/
5
- # https://github.com/redis/redis-rb
6
- def initialize *args
7
- args = [url: Liza.const(:net_box).clients.get(:redis_url)] if args.empty?
8
- log "Connecting to #{args}"
9
- @conn = Redis.new *args
10
- end
11
-
12
- attr_reader :conn
3
+ # https://redis.io/
4
+ # https://github.com/redis/redis-rb
5
+ def initialize *args
6
+ args = [url: NetBox[:client].get(:redis_url)] if args.empty?
7
+ log "Connecting to #{args}"
8
+ @conn = Redis.new(*args)
9
+ end
13
10
 
14
- def call cmd_name, *args
15
- t = Time.now
16
- result = @conn.send cmd_name, *args
11
+ attr_reader :conn
17
12
 
18
- result
19
- ensure
20
- log "#{t.diff}s | #{cmd_name} | #{args}"
21
- end
13
+ def call cmd_name, *args
14
+ t = Time.now
15
+ result = @conn.send cmd_name, *args
22
16
 
23
- def now
24
- call :time
25
- end
17
+ result
18
+ ensure
19
+ log "#{t.diff}s | #{cmd_name} | #{args}"
20
+ end
26
21
 
22
+ def now
23
+ call :time
27
24
  end
25
+
28
26
  end
@@ -1,29 +1,27 @@
1
- class NetSystem
2
- class RedisClientTest < ClientTest
1
+ class NetSystem::RedisClientTest < NetSystem::ClientTest
3
2
 
4
- def subject
5
- @subject ||= subject_class.new
6
- end
7
-
8
- test :subject_class do
9
- assert subject_class == Liza::RedisClient
10
- end
3
+ def subject
4
+ @subject ||= subject_class.new
5
+ end
11
6
 
12
- test :subject do
13
- assert subject.conn.class == Redis
14
- end
7
+ test :subject_class do
8
+ assert subject_class == NetSystem::RedisClient
9
+ end
15
10
 
16
- test :call do
17
- result = subject.call :keys
18
- assert result.class == Array
19
- assert result.count == 0
20
- end
11
+ test :subject do
12
+ assert subject.conn.class == Redis
13
+ end
21
14
 
22
- test :now do
23
- result = subject.now
24
- assert result.class == Array
25
- assert result.map(&:class) == [Integer, Integer]
26
- end
15
+ test :call do
16
+ result = subject.call :keys
17
+ assert result.class == Array
18
+ assert result.count == 0
19
+ end
27
20
 
21
+ test :now do
22
+ result = subject.now
23
+ assert result.class == Array
24
+ assert result.map(&:class) == [Integer, Integer]
28
25
  end
26
+
29
27
  end