lizarb 1.0.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +14 -3
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/app_bench.rb +5 -0
  10. data/app/dev/benches/app_bench_test.rb +7 -0
  11. data/app/dev/benches/loops_bench.rb +183 -0
  12. data/app/dev/benches/loops_bench_test.rb +11 -0
  13. data/app/dev/commands/calculator_command.rb +69 -0
  14. data/app/dev/commands/calculator_command_test.rb +58 -0
  15. data/app/dev/commands/circle_command.rb +70 -0
  16. data/app/dev/commands/circle_command_test.rb +76 -0
  17. data/app/dev/commands/narrative_method_command.rb +60 -0
  18. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  19. data/app/dev/commands/new_command.rb +1 -61
  20. data/app/dev/commands/quadratic_command.rb +66 -0
  21. data/app/dev/commands/quadratic_command_test.rb +47 -0
  22. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  23. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  24. data/app/dev/generators/bench_generator.rb +18 -0
  25. data/app/dev/generators/bench_generator_test.rb +12 -0
  26. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  27. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  28. data/app/dev/generators/command_generator.rb +18 -0
  29. data/app/dev/generators/command_generator_test.rb +12 -0
  30. data/app/dev/generators/record_generator.rb +46 -0
  31. data/app/dev/generators/record_generator_test.rb +12 -0
  32. data/app/dev/generators/request_generator.rb +63 -0
  33. data/app/dev/generators/request_generator_test.rb +12 -0
  34. data/app/net/databases/redis_db_test.rb +2 -2
  35. data/app/net/databases/sqlite_db_test.rb +2 -2
  36. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  37. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  38. data/app/net/records/post_record.rb +4 -0
  39. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  40. data/app/net/records/user_record.rb +4 -0
  41. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  42. data/app/net_box.rb +2 -2
  43. data/app/web/requests/api_request.rb +8 -7
  44. data/app/web/requests/assets_request.rb +12 -13
  45. data/app/web/requests/root_request.rb +6 -7
  46. data/app/web/requests/root_request_test.rb +1 -1
  47. data/app/web_box.rb +8 -0
  48. data/app_new/Procfile +1 -1
  49. data/exe/lrb +3 -0
  50. data/lib/app.rb +18 -14
  51. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  52. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  53. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  54. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  55. data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench_test.rb} +2 -2
  56. data/lib/dev_system/dev/controllers/command/bench_command.rb +34 -0
  57. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  58. data/lib/dev_system/dev/controllers/command/generate_command.rb +35 -0
  59. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  60. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  61. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +14 -0
  62. data/lib/dev_system/dev/controllers/command/terminal_command.rb +24 -0
  63. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  64. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  65. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  66. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  67. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  68. data/lib/dev_system/dev/controllers/generators/app_generator.rb +96 -0
  69. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  70. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  71. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  72. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  73. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  74. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  75. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  76. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  77. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  78. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  79. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  80. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  81. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  82. data/lib/dev_system/dev/controllers/shell/file_shell.rb +59 -0
  83. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +150 -0
  84. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  85. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  86. data/lib/dev_system/dev/controllers/shell.rb +31 -0
  87. data/lib/dev_system/dev/controllers/shell_test.rb +46 -0
  88. data/lib/dev_system/dev/controllers/{command/dev_command.rb → terminal/irb_terminal.rb} +2 -2
  89. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  90. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  91. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  92. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  93. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  94. data/lib/dev_system/dev/dev_box.rb +3 -0
  95. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  96. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  97. data/lib/lerb.rb +106 -0
  98. data/lib/liza/base/controller.rb +2 -0
  99. data/lib/liza/base/panel.rb +6 -5
  100. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  101. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  102. data/lib/liza/meta/part_extension.rb +6 -1
  103. data/lib/liza/ruby_test.rb +9 -0
  104. data/lib/liza/ruby_tests/module_test.rb +21 -0
  105. data/lib/liza/ruby_tests/string_test.rb +59 -0
  106. data/lib/liza/test/test.rb +3 -1
  107. data/lib/liza/test/test_test.rb +108 -15
  108. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  109. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  110. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  111. data/lib/liza/test_parts/test_log_part.rb +124 -0
  112. data/lib/liza/test_parts/test_subject_part.rb +6 -1
  113. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  114. data/lib/liza/unit.rb +2 -0
  115. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  116. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  117. data/lib/liza.rb +40 -7
  118. data/lib/lizarb/ruby/class.rb +2 -0
  119. data/lib/lizarb/ruby/module.rb +17 -0
  120. data/lib/lizarb/ruby/proc.rb +12 -0
  121. data/lib/lizarb/ruby/string.rb +26 -2
  122. data/lib/lizarb/version.rb +1 -1
  123. data/lib/lizarb.rb +24 -2
  124. data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
  125. data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
  126. data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
  127. data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
  128. data/lib/net_system/net/controllers/client.rb +5 -0
  129. data/lib/net_system/net/controllers/{model_test.rb → client_test.rb} +2 -2
  130. data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
  131. data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
  132. data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
  133. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
  134. data/lib/net_system/net/controllers/database.rb +6 -6
  135. data/lib/net_system/net/controllers/record.rb +31 -0
  136. data/lib/net_system/net/controllers/{adapter_test.rb → record_test.rb} +2 -2
  137. data/lib/net_system/net/net_box.rb +5 -5
  138. data/lib/net_system/net/net_box_test.rb +1 -1
  139. data/lib/net_system/net/panels/client_panel.rb +5 -0
  140. data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
  141. data/lib/web_system/dev/rack_command.rb +26 -0
  142. data/lib/web_system/dev/request_command.rb +143 -0
  143. data/lib/web_system/dev/web_command.rb +3 -34
  144. data/lib/web_system/web/controllers/rack.rb +8 -0
  145. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  146. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  147. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  148. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  149. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  150. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  151. data/lib/web_system/web/panels/request_panel.rb +51 -32
  152. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  153. data/lib/web_system/web/web_box.rb +12 -0
  154. data/lizarb.gemspec +2 -2
  155. data/tmp/.gitkeep +0 -0
  156. metadata +110 -31
  157. data/app/dev/commands/example_command.rb +0 -57
  158. data/app/dev/commands/example_command_test.rb +0 -43
  159. data/app/dev/commands/macro_child_command.rb +0 -32
  160. data/app/dev/commands/macro_child_command_test.rb +0 -7
  161. data/app/dev/commands/macro_parent_command.rb +0 -70
  162. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  163. data/app/dev/commands/my_command.rb +0 -7
  164. data/app/dev/commands/my_command_test.rb +0 -7
  165. data/app/net/models/post_model.rb +0 -4
  166. data/app/net/models/user_model.rb +0 -4
  167. data/lib/liza/test_parts/test_context_part.rb +0 -81
  168. data/lib/net_system/net/controllers/adapter.rb +0 -5
  169. data/lib/net_system/net/controllers/model.rb +0 -31
  170. data/lib/net_system/net/panels/adapter_panel.rb +0 -5
@@ -0,0 +1,150 @@
1
+ class DevSystem::FileShellTest < DevSystem::ShellTest
2
+
3
+ # before do
4
+ # puts tmp.to_s.magenta
5
+ # end
6
+
7
+ def tmp_dir
8
+ @tmp_dir ||= begin
9
+ name = self.class.name.split("::").map(&:snakefy).join "_"
10
+ time = Time.now.strftime "%Y%m%d_%H%M%S"
11
+ random = SecureRandom.hex 4
12
+ ret = Pathname.new(Dir.pwd).join "tmp/test_#{App.mode}_#{name}_#{time}_#{random}"
13
+ FileUtils.mkdir_p ret
14
+ log "Created tmp_dir: #{ret}"
15
+ ret
16
+ end
17
+ end
18
+
19
+ after do
20
+ # NOTE: @tmp_dir does not create a new directory for each test
21
+ if @tmp_dir
22
+ FileUtils.rm_rf @tmp_dir
23
+ log "Removed tmp_dir: #{@tmp_dir}"
24
+ end
25
+ end
26
+
27
+ #
28
+
29
+ test :subject_class do
30
+ assert subject_class == DevSystem::FileShell
31
+ end
32
+
33
+ test :settings do
34
+ assert subject_class.log_level == :normal
35
+ assert subject_class.log_color == :green
36
+ end
37
+
38
+ #
39
+
40
+ test :subject_class, :exist?, :true do
41
+ assert subject_class.exist? __FILE__
42
+ end
43
+
44
+ test :subject_class, :exist?, :false do
45
+ refute subject_class.exist? "does_not_exist_#{rand 999}"
46
+ end
47
+
48
+ test :subject_class, :exist?, :raise do
49
+ assert_raises ArgumentError do
50
+ subject_class.exist? nil
51
+ end
52
+
53
+ assert_raises ArgumentError do
54
+ subject_class.exist? ""
55
+ end
56
+ end
57
+
58
+ #
59
+
60
+ test :subject_class, :size, true do
61
+ assert subject_class.size(__FILE__).positive?
62
+ end
63
+
64
+ test :subject_class, :size, :raise do
65
+ assert_raises ArgumentError do
66
+ subject_class.size nil
67
+ end
68
+
69
+ assert_raises ArgumentError do
70
+ subject_class.size ""
71
+ end
72
+
73
+ assert_raises ArgumentError do
74
+ subject_class.size "does_not_exist_#{rand 999}"
75
+ end
76
+ end
77
+
78
+ #
79
+
80
+ test :subject_class, :directory?, true do
81
+ assert subject_class.directory? Dir.pwd
82
+ end
83
+
84
+ test :subject_class, :directory?, false do
85
+ refute subject_class.directory? __FILE__
86
+ refute subject_class.directory? "does_not_exist"
87
+ end
88
+
89
+ test :subject_class, :directory?, :raise do
90
+ assert_raises ArgumentError do
91
+ subject_class.directory? nil
92
+ end
93
+
94
+ assert_raises ArgumentError do
95
+ subject_class.directory? ""
96
+ end
97
+ end
98
+
99
+ test :subject_class, :file?, true do
100
+ assert subject_class.file? __FILE__
101
+ end
102
+
103
+ test :subject_class, :file?, false do
104
+ refute subject_class.file? Dir.pwd
105
+ refute subject_class.file? "does_not_exist_#{rand 999}"
106
+ end
107
+
108
+ test :subject_class, :file?, :raise do
109
+ assert_raises ArgumentError do
110
+ subject_class.file? nil
111
+ end
112
+
113
+ assert_raises ArgumentError do
114
+ subject_class.file? ""
115
+ end
116
+ end
117
+
118
+ #
119
+
120
+ test :subject_class, :touch, true do
121
+ path = tmp_dir.join "touch_#{Time.now.to_i}"
122
+ refute subject_class.exist? path
123
+
124
+ assert subject_class.touch path
125
+ assert subject_class.exist? path
126
+ end
127
+
128
+ test :subject_class, :touch, :raise do
129
+ assert_raises ArgumentError do
130
+ subject_class.touch nil
131
+ end
132
+
133
+ assert_raises ArgumentError do
134
+ subject_class.touch ""
135
+ end
136
+ end
137
+
138
+ #
139
+
140
+ test :subject_class, :gitkeep do
141
+ path = tmp_dir.join "gitkeep_#{Time.now.to_i}"
142
+ refute subject_class.exist? path
143
+
144
+ assert subject_class.gitkeep path
145
+ assert subject_class.exist? path
146
+ end
147
+
148
+ #
149
+
150
+ end
@@ -0,0 +1,23 @@
1
+ class DevSystem::TextShell < DevSystem::FileShell
2
+
3
+ set :create_dir, true
4
+
5
+ def self.read path
6
+ log "Reading #{path}"
7
+ _raise_if_blank path
8
+ _raise_if_not_exists path
9
+
10
+ File.read path
11
+ end
12
+
13
+ def self.write path, content, create_dir: nil
14
+ log "Writing #{content.to_s.size} characters (#{content.encoding}) to #{path}"
15
+ _raise_if_blank path
16
+
17
+ create_dir = get :create_dir if create_dir.nil?
18
+ DevSystem::DirShell.create File.dirname path if create_dir
19
+
20
+ File.write path, content
21
+ end
22
+
23
+ end
@@ -0,0 +1,84 @@
1
+ class DevSystem::TextShellTest < DevSystem::FileShellTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::TextShell
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ #
13
+
14
+ test :subject_class, :read, true do
15
+ assert subject_class.read(__FILE__).size.positive?
16
+ end
17
+
18
+ test :subject_class, :read, :raise do
19
+ assert_raises ArgumentError do
20
+ subject_class.read nil
21
+ end
22
+
23
+ assert_raises ArgumentError do
24
+ subject_class.read ""
25
+ end
26
+
27
+ assert_raises ArgumentError do
28
+ subject_class.read "does_not_exist_#{rand 999}"
29
+ end
30
+ end
31
+
32
+ #
33
+
34
+ test :subject_class, :write, :raise do
35
+ assert_raises ArgumentError do
36
+ subject_class.write nil, "content"
37
+ end
38
+
39
+ assert_raises ArgumentError do
40
+ subject_class.write "", "content"
41
+ end
42
+ end
43
+
44
+ test :subject_class, :write, true do
45
+ path = tmp_dir.join "write_#{Time.now.to_i}"
46
+
47
+ refute subject_class.exist? path
48
+ assert subject_class.write path, "content"
49
+
50
+ assert subject_class.exist? path
51
+ assert subject_class.read(path) == "content"
52
+ end
53
+
54
+ test :subject_class, :write, :encoding do
55
+ path = tmp_dir.join "write_#{Time.now.to_i}"
56
+ s1 = "content"
57
+
58
+ refute subject_class.exist? path
59
+ assert subject_class.write path, s1
60
+
61
+ s2 = subject_class.read path
62
+ assert_equality s1, s2
63
+ assert_equality s1.encoding, s2.encoding
64
+
65
+ assert_equality s1.encoding, Encoding::UTF_8
66
+ assert_equality s2.encoding, Encoding::UTF_8
67
+ end
68
+
69
+ test :subject_class, :write, :create_dir do
70
+ path = tmp_dir.join "write_dir_#{Time.now.to_i}/a/b/c"
71
+
72
+ refute subject_class.exist? path
73
+
74
+ assert_raises Errno::ENOENT do
75
+ assert subject_class.write path, "content", create_dir: false
76
+ end
77
+
78
+ assert subject_class.write path, "content", create_dir: true
79
+
80
+ assert subject_class.exist? path
81
+ assert subject_class.read(path) == "content"
82
+ end
83
+
84
+ end
@@ -0,0 +1,31 @@
1
+ class DevSystem::Shell < Liza::Controller
2
+
3
+ # Check if the current platform is Windows
4
+ def self.windows?
5
+ @windows || Gem.win_platform?
6
+ end
7
+
8
+ # Check if the current platform is Unix or Unix-like
9
+ def self.unix?
10
+ @unix || !windows?
11
+ end
12
+
13
+ # Check if the current platform is Linux
14
+ def self.linux?
15
+ @linux || (unix? && RbConfig::CONFIG['host_os'].include?("linux"))
16
+ end
17
+
18
+ # Check if the current platform is Mac OS
19
+ def self.mac?
20
+ @mac || (unix? && RbConfig::CONFIG['host_os'].include?("darwin"))
21
+ end
22
+
23
+ # Return the current operating system as a symbol
24
+ def self.os
25
+ return :windows if windows?
26
+ return :linux if linux?
27
+ return :mac if mac?
28
+ :unix
29
+ end
30
+
31
+ end
@@ -0,0 +1,46 @@
1
+ class DevSystem::ShellTest < Liza::ControllerTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::Shell
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :green
10
+ end
11
+
12
+ #
13
+
14
+ test :subject_class, :windows? do
15
+ original = subject_class.windows?
16
+ subject_class.instance_variable_set(:@windows, true)
17
+ assert subject_class.windows?
18
+ ensure
19
+ subject_class.instance_variable_set(:@windows, original)
20
+ end
21
+
22
+ test :subject_class, :unix? do
23
+ original = subject_class.unix?
24
+ subject_class.instance_variable_set(:@unix, true)
25
+ assert subject_class.unix?
26
+ ensure
27
+ subject_class.instance_variable_set(:@unix, original)
28
+ end
29
+
30
+ test :subject_class, :linux? do
31
+ original = subject_class.linux?
32
+ subject_class.instance_variable_set(:@linux, true)
33
+ assert subject_class.linux?
34
+ ensure
35
+ subject_class.instance_variable_set(:@linux, original)
36
+ end
37
+
38
+ test :subject_class, :mac? do
39
+ original = subject_class.mac?
40
+ subject_class.instance_variable_set(:@mac, true)
41
+ assert subject_class.mac?
42
+ ensure
43
+ subject_class.instance_variable_set(:@mac, original)
44
+ end
45
+
46
+ end
@@ -1,8 +1,8 @@
1
1
  class DevSystem
2
- class DevCommand < Command
2
+ class IrbTerminal < Terminal
3
3
 
4
4
  def self.call args
5
- log :higher, "Called #{self} with args #{args}"
5
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
6
 
7
7
  # https://github.com/ruby/ruby/blob/master/lib/irb.rb
8
8
  require "irb"
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class IrbTerminalTest < TerminalTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::IrbTerminal
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class DevSystem
2
+ class PryTerminal < Terminal
3
+
4
+ def self.call args
5
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+
7
+ require "pry"
8
+ Pry.start
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class PryTerminalTest < TerminalTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::PryTerminal
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ class DevSystem
2
+ class Terminal < Liza::Controller
3
+
4
+ # def self.call args
5
+ # new.call args
6
+ # end
7
+
8
+ # def initialize args
9
+ # @args = args
10
+ # end
11
+
12
+ # attr_reader :args
13
+
14
+ # def call args
15
+ #
16
+ # end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class TerminalTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::Terminal
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+
13
+ end
14
+ end
@@ -2,6 +2,9 @@ class DevSystem
2
2
  class DevBox < Liza::Box
3
3
  has_panel :command, :commands
4
4
  has_controller :command, :commands
5
+ has_controller :shell, :commands
6
+ has_controller :bench, :commands
7
+ has_controller :terminal, :commands
5
8
 
6
9
  has_panel :log, :logs
7
10
 
@@ -2,9 +2,29 @@ class DevSystem
2
2
  class CommandPanel < Liza::Panel
3
3
 
4
4
  def call args
5
- command_klass = Liza.const "#{args[0]}_command"
5
+ # 1. LOG
6
+
7
+ log "call #{args}"
8
+
9
+ # 2. FIND command
10
+
11
+ return call_not_found args if args.none?
12
+
13
+ command = args[0]
14
+
15
+ log({command:})
16
+
17
+ command_klass = Liza.const "#{command}_command"
18
+
19
+ # 3. CALL
20
+
6
21
  command_klass.call args[1..-1]
22
+ rescue Liza::ConstNotFound
23
+ call_not_found args
7
24
  end
8
25
 
26
+ def call_not_found args
27
+ Liza::NotFoundCommand.call args
28
+ end
9
29
  end
10
30
  end
@@ -3,7 +3,7 @@ class DevSystem
3
3
 
4
4
  # https://rubyapi.org/3.1/o/logger
5
5
  def call string
6
- puts string
6
+ puts "lizarb #{Lizarb.thread_id.to_s.rjust_zeroes 3} #{string}"
7
7
  end
8
8
 
9
9
  end
data/lib/lerb.rb ADDED
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ # https://docs.ruby-lang.org/en/3.2/ERB.html
4
+ require "erb"
5
+
6
+ class LERB < ERB
7
+ class Error < StandardError; end
8
+ class BuildError < Error; end
9
+ class ExecutionError < Error; end
10
+
11
+ # loaders
12
+
13
+ def self.load path_radical
14
+ load_from_folder(path_radical) + load_from_file("#{path_radical}.rb")
15
+ end
16
+
17
+ def self.load_from_file path
18
+ ret = []
19
+
20
+ fname = path
21
+ return ret unless File.exist? path
22
+
23
+ lines = File.readlines fname
24
+
25
+ lineno = lines.index "__END__\n"
26
+ return ret if lineno.nil?
27
+
28
+ content = lines[lineno+1..-1].join
29
+ array = content.split(/^# (\w*).(\w*).(\w*)$/)
30
+ # => ["", "a", "html", "erb", "\n<html>\n<a></a>\n</html>\n", "b", "html", "erb", "\n<html>\n<b></b>\n</html>"]
31
+
32
+ while (chunk = array.pop 4; chunk.size == 4)
33
+ # => ["b", "html", "erb", "\n<html>\n<b></b>\n</html>"]
34
+ # => ["a", "html", "erb", "\n<html>\n<a></a>\n</html>\n"]
35
+ key = "#{chunk[0]}.#{chunk[1]}.#{chunk[2]}"
36
+ content = chunk[3]
37
+ ret.push new :file, key, content, fname, lineno
38
+ end
39
+
40
+ ret
41
+ end
42
+
43
+ def self.load_from_folder path
44
+ ret = []
45
+
46
+ lineno = 0
47
+ fnames = Dir.glob "#{path}/*.*.erb"
48
+ fnames.map do |fname|
49
+ key = fname.split("/").last
50
+ content = File.read fname
51
+ ret.push new :folder, key, content, fname, lineno
52
+ end
53
+
54
+ ret
55
+ end
56
+
57
+ # format
58
+
59
+ TAG_FORMATS = %w|xml html|
60
+
61
+ def tags?
62
+ TAG_FORMATS.include? format
63
+ end
64
+
65
+ # source
66
+
67
+ SOURCES = %i|file folder|
68
+
69
+ def file?
70
+ @source == :file
71
+ end
72
+
73
+ def folder?
74
+ @source == :folder
75
+ end
76
+
77
+ # constructor
78
+
79
+ TRIM_MODE = "<>-"
80
+
81
+ attr_reader :source, :key, :name, :format
82
+
83
+ def initialize source, key, content, filename, lineno
84
+ raise BuildError, "source :#{source} must be one of #{SOURCES}" unless SOURCES.include? source
85
+
86
+ segments = key.split("/").last.split(".")
87
+ name, format = segments[0..1]
88
+
89
+ # raise BuildError, "key '#{key}' must be formatted as <name>.<format>.erb" unless segments.count == 3
90
+ # raise BuildError, "key '#{key}' must be formatted as <name>.<format>.erb" unless segments[2] == "erb"
91
+ raise BuildError, "key '#{key}' has an invalid format '#{format}'" unless format.gsub(/[^a-z0-9]/, "") == format
92
+
93
+ super content, trim_mode: TRIM_MODE
94
+ @source, @key, @name, @format, self.filename, self.lineno = source, key, name, format, filename, lineno
95
+ end
96
+
97
+ # result
98
+
99
+ def result the_binding, receiver=:unset
100
+ super the_binding
101
+ rescue NameError => e
102
+ raise unless e.receiver == receiver
103
+ message = "ERB template for a #{e.receiver.class} instance could not find method '#{e.name}'"
104
+ raise ExecutionError, message, [e.backtrace[0]]
105
+ end
106
+ end
@@ -1,5 +1,7 @@
1
1
  module Liza
2
2
  class Controller < Unit
3
+ part :controller_renderer
4
+
3
5
  inherited_explicitly_sets_system
4
6
 
5
7
  def self.on_connected box_klass, panel
@@ -18,20 +18,21 @@ module Liza
18
18
  @name = name
19
19
  end
20
20
 
21
- def log string
21
+ def log log_level = :normal, string
22
+ raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
23
+ return unless log_level? log_level
24
+
22
25
  source = box.to_s
23
26
 
24
27
  x = source.size
25
-
26
28
  source = source.bold.colorize log_color
27
29
 
28
30
  y = source.size
29
-
30
31
  source = "#{source}.#{@name}".ljust(LOG_JUST+y-x)
31
32
 
32
33
  string = "#{source} #{string}"
33
-
34
- super string
34
+
35
+ DevBox.logs.call string
35
36
  end
36
37
 
37
38
  end