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
@@ -0,0 +1,143 @@
1
+ class WebSystem::RequestCommand < Liza::Command
2
+
3
+ VALID_ACTIONS = %w[find get post]
4
+
5
+ def self.call(args)
6
+ log "Called #{self}.#{__method__} with args #{args}"
7
+ new.call(args)
8
+ end
9
+
10
+ # instance methods
11
+
12
+ def call(args)
13
+ log "Called #{self}.#{__method__} with args #{args}"
14
+
15
+ @command = args.shift
16
+ @args = args
17
+
18
+ return help unless VALID_ACTIONS.include? @command
19
+ perform
20
+ rescue StandardError => error
21
+ @error = error
22
+ handle
23
+ end
24
+
25
+ def perform
26
+ log "Called #{self}.#{__method__}"
27
+
28
+ case @command
29
+ when "find"
30
+ find
31
+ when "get"
32
+ get_request
33
+ when "post"
34
+ post_request
35
+ end
36
+ end
37
+
38
+ def handle
39
+ log "Called #{self}.#{__method__}"
40
+ log render "error.txt"
41
+ end
42
+
43
+ def help
44
+ log "Called #{self}.#{__method__}"
45
+ log render "help.txt"
46
+ end
47
+
48
+ # actions
49
+
50
+ def find
51
+ log "Called #{self}.#{__method__}"
52
+ path = @args.first
53
+
54
+ @env = {}
55
+ @env["REQUEST_PATH"] = path
56
+
57
+ request_panel.find @env
58
+
59
+ @request_class = @env["LIZA_REQUEST_CLASS"] || raise("No request class found")
60
+
61
+ puts render "find.txt"
62
+ end
63
+
64
+ def get_request
65
+ log "Called #{self}.#{__method__}"
66
+ path = @args.first
67
+
68
+ @env = {}
69
+ @env["REQUEST_METHOD"] = "GET"
70
+ @env["REQUEST_PATH"] = path
71
+
72
+ @status, @headers, @body = request_panel.call @env
73
+ log "STATUS #{@status} with #{@headers.count} headers and a #{@body.first.size} byte body"
74
+ puts render "response.http"
75
+ end
76
+
77
+ def post_request
78
+ log "Called #{self}.#{__method__}"
79
+ path = @args.first
80
+
81
+ @env = {}
82
+ @env["REQUEST_METHOD"] = "POST"
83
+ @env["REQUEST_PATH"] = path
84
+
85
+ @status, @headers, @body = request_panel.call @env
86
+ log "STATUS #{@status} with #{@headers.count} headers and a #{@body.first.size} byte body"
87
+ puts render "response.http"
88
+ end
89
+
90
+ # helpers
91
+
92
+ def request_panel
93
+ @request_panel ||= WebBox[:request]
94
+ end
95
+ end
96
+
97
+ __END__
98
+
99
+ # success.txt.erb
100
+
101
+ RESULT:
102
+
103
+ class <%= @result.class %>
104
+ value <%= @result %>
105
+
106
+ # error.txt.erb
107
+
108
+ ERROR:
109
+
110
+ class <%= @error.class %>
111
+ message <%= @error.message %>
112
+ backtrace <%= @error.backtrace.select { |s| @stop = true if s.include?("/exe/lizarb:"); !defined? @stop }.join "\n " %>
113
+
114
+ # help.txt.erb
115
+
116
+ USAGE:
117
+
118
+ liza request find /path/to/action.format
119
+ liza request get /path/to/action.format
120
+ liza request post /path/to/action.format
121
+
122
+ # find.txt.erb
123
+
124
+ ENV:
125
+ <% @env.each do |k, v| %>
126
+ env["<%= k %>"] = <%= v.inspect -%>
127
+ <% end %>
128
+
129
+ REQUEST CLASS:
130
+
131
+ # <%= @request_class.source_location.join ":" %>
132
+ class <%= @request_class %> < <%= @request_class.superclass %>
133
+ # ...
134
+ end
135
+
136
+ # response.http.erb
137
+
138
+ <%= @status %>
139
+ <% @headers.each do |k, v| -%>
140
+ <%= k %>: <%= v %>
141
+ <% end -%>
142
+
143
+ <%= @body.first %>
@@ -1,42 +1,9 @@
1
- class WebSystem
2
- class WebCommand < Liza::Command
3
-
4
- set :files, App.root.join("web_files")
5
- set :host, "localhost"
6
- set :port, 3000
7
-
8
- def self.call args
9
- log :higher, "Called #{self} with args #{args}"
10
-
11
- host = get :host
12
- port = get :port
13
-
14
- args.each do |arg|
15
- host = arg.split("=")[1] if arg.start_with? "h="
16
- port = arg.split("=")[1] if arg.start_with? "p="
17
- end
18
-
19
- if App.mode == :code
20
- ENV["RACK_ENV"] = "development"
21
- rack_app = method :_call
22
- else
23
- ENV["RACK_ENV"] = "production"
24
- rack_app = ::WebBox.requests
25
- end
26
-
27
- rack_files = Rack::Files.new get(:files)
28
- rack_app = Rack::Cascade.new [rack_files, rack_app]
29
-
30
- require "rack/handler/puma"
31
- Rack::Handler::Puma.run rack_app, Host: host, Port: port
32
- end
33
-
34
- def self._call app
35
- App.reload do
36
- log "reloading"
37
- return ::WebBox.requests.call app
38
- end
39
- end
1
+ class WebSystem::WebCommand < Liza::Command
40
2
 
3
+ def self.call args
4
+ log "args #{args}"
5
+ log "DEPRECATED: please use `lizarb rack` instead"
6
+ RackCommand.call args
41
7
  end
8
+
42
9
  end
@@ -0,0 +1,6 @@
1
+ class WebSystem::Rack < Liza::Controller
2
+
3
+ # def self.call rack_app, host, port
4
+ # end
5
+
6
+ end
@@ -0,0 +1,16 @@
1
+ class WebSystem::RackTest < Liza::ControllerTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == WebSystem::Rack
5
+ end
6
+
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :blue
10
+ end
11
+
12
+ # test :call do
13
+ # todo "write this"
14
+ # end
15
+
16
+ end
@@ -1,18 +1,15 @@
1
- class WebSystem
2
- class ClientErrorRequest < Request
1
+ class WebSystem::ClientErrorRequest < WebSystem::Request
3
2
 
4
- def self.call env
5
- status = 400
3
+ def self.call env
4
+ status = 400
6
5
 
7
- headers = {
8
- "Framework" => "Liza #{Lizarb::VERSION}"
9
- }
6
+ headers = {
7
+ "Framework" => "Liza #{Lizarb::VERSION}"
8
+ }
10
9
 
11
- body = "Client Error #{status} - #{env["LIZA_PATH"]}"
12
-
13
- log status
14
- [status, headers, [body]]
15
- end
10
+ body = "Client Error #{status} - #{env["LIZA_PATH"]}"
16
11
 
12
+ [status, headers, [body]]
17
13
  end
14
+
18
15
  end
@@ -1,18 +1,15 @@
1
- class WebSystem
2
- class NotFoundRequest < Request
1
+ class WebSystem::NotFoundRequest < WebSystem::Request
3
2
 
4
- def self.call env
5
- status = 404
3
+ def self.call env
4
+ status = 404
6
5
 
7
- headers = {
8
- "Framework" => "Liza #{Lizarb::VERSION}"
9
- }
6
+ headers = {
7
+ "Framework" => "Liza #{Lizarb::VERSION}"
8
+ }
10
9
 
11
- body = "Client Error #{status} - #{env["LIZA_PATH"]}"
12
-
13
- log status
14
- [status, headers, [body]]
15
- end
10
+ body = "Client Error #{status} - #{env["LIZA_PATH"]}"
16
11
 
12
+ [status, headers, [body]]
17
13
  end
14
+
18
15
  end
@@ -1,20 +1,17 @@
1
- class WebSystem
2
- class ServerErrorRequest < Request
1
+ class WebSystem::ServerErrorRequest < WebSystem::Request
3
2
 
4
- def self.call env
5
- status = 500
3
+ def self.call env
4
+ status = 500
6
5
 
7
- headers = {
8
- "Framework" => "Liza #{Lizarb::VERSION}"
9
- }
6
+ headers = {
7
+ "Framework" => "Liza #{Lizarb::VERSION}"
8
+ }
10
9
 
11
- e = env["LIZA_ERROR"]
10
+ e = env["LIZA_ERROR"]
12
11
 
13
- body = "Server Error #{status} - #{e.class} - #{e.message}"
14
-
15
- log status
16
- [status, headers, [body]]
17
- end
12
+ body = "Server Error #{status} - #{e.class} - #{e.message}"
18
13
 
14
+ [status, headers, [body]]
19
15
  end
16
+
20
17
  end
@@ -1,5 +1,3 @@
1
- class WebSystem
2
- class Request < Liza::Controller
1
+ class WebSystem::Request < Liza::Controller
3
2
 
4
- end
5
3
  end
@@ -1,18 +1,16 @@
1
- class WebSystem
2
- class RequestTest < Liza::ControllerTest
1
+ class WebSystem::RequestTest < Liza::ControllerTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == WebSystem::Request
6
- end
3
+ test :subject_class do
4
+ assert subject_class == WebSystem::Request
5
+ end
7
6
 
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :blue
11
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :blue
10
+ end
12
11
 
13
- # test :call do
14
- # todo "write this"
15
- # end
12
+ # test :call do
13
+ # todo "write this"
14
+ # end
16
15
 
17
- end
18
16
  end
@@ -0,0 +1,42 @@
1
+ class WebSystem::RackPanel < Liza::Panel
2
+
3
+ def call strategy, host, port
4
+ puts
5
+ log({strategy:, host:, port:})
6
+
7
+ strategy ||= get :strategy
8
+ host ||= get :host
9
+ port ||= 3000
10
+ files ||= get :files
11
+
12
+ log({strategy:, host:, port:})
13
+
14
+ x = App.mode == :code ? "development" : "production"
15
+ ENV["RACK_ENV"] = x
16
+ rack_app = send "get_rack_app_#{x}"
17
+
18
+ rack_files = Object::Rack::Files.new files
19
+ rack_app = Object::Rack::Cascade.new [rack_files, rack_app]
20
+
21
+ # TODO: PumaRack
22
+ # handler = Liza.const(:"#{strategy}_rack")
23
+
24
+ require "rack/handler/puma"
25
+ handler = Object::Rack::Handler::Puma
26
+ handler.run rack_app, Host: host, Port: port
27
+ end
28
+
29
+ def get_rack_app_production()= WebBox[:request]
30
+
31
+ def get_rack_app_development
32
+ Proc.new do |env|
33
+ ret = nil
34
+ App.reload do
35
+ log "reloading"
36
+ ret = get_rack_app_production.call env
37
+ end
38
+ ret
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,12 @@
1
+ class WebSystem::RackPanelTest < Liza::PanelTest
2
+
3
+ test :settings do
4
+ assert subject_class.log_level == :normal
5
+ assert subject_class.log_color == :blue
6
+ end
7
+
8
+ # test :call do
9
+ # todo "write this"
10
+ # end
11
+
12
+ end
@@ -1,55 +1,72 @@
1
- class WebSystem
2
- class RequestPanel < Liza::Panel
1
+ class WebSystem::RequestPanel < Liza::Panel
2
+
3
+ def call env
4
+ t = Time.now
5
+ request_klass = find env
6
+ ret = request_klass.call env
7
+ _html_beautify env, ret
8
+ ret
9
+ rescue => e
10
+ request_klass = WebSystem::ServerErrorRequest
11
+ env["LIZA_ERROR"] = e
12
+
13
+ ret = request_klass.call env
14
+ ensure
15
+ log "#{ret[0]} with #{ret[2].first.size} bytes in #{t.diff}s"
16
+ puts
17
+ ret
18
+ end
3
19
 
4
- def call env
5
- puts
20
+ #
6
21
 
7
- # 1. LOG GET /
22
+ def find env
23
+ _prepare env
8
24
 
9
- log "#{env["REQUEST_METHOD"]} #{env["REQUEST_PATH"]}"
25
+ path = env["LIZA_PATH"]
10
26
 
11
- # 2. PREPARE env
27
+ segments = env["LIZA_SEGMENTS"].dup
28
+ request = segments.shift || "root"
29
+ action = segments.shift || "index"
12
30
 
13
- path = env["REQUEST_PATH"]
31
+ env["LIZA_REQUEST"] = request
32
+ env["LIZA_ACTION"] = action
33
+ format = env["LIZA_FORMAT"]
14
34
 
15
- path, _sep, format = path.lpartition "."
16
- format = "html" if format.empty?
35
+ log({request:, action:, format:})
17
36
 
18
- segments = Array path.split("/")[1..-1]
37
+ env["LIZA_REQUEST_CLASS"] = _find_request_class request
38
+ end
19
39
 
20
- case segments.count
21
- when 0
22
- request, action = "root", "root"
23
- when 1
24
- request, action = "root", segments[0]
25
- else
26
- request, action = segments[0..1]
27
- end
40
+ def _find_request_class request
41
+ Liza.const "#{request}_request"
42
+ rescue NameError
43
+ WebSystem::NotFoundRequest
44
+ end
28
45
 
29
- env["LIZA_PATH"] = path
30
- env["LIZA_REQUEST"] = request
31
- env["LIZA_ACTION"] = action
32
- env["LIZA_FORMAT"] = format
46
+ #
33
47
 
34
- log({request:, action:, format:})
48
+ def _html_beautify env, ret
49
+ return unless defined? HtmlBeautifier
50
+ return unless env["LIZA_FORMAT"] == "html"
35
51
 
36
- # 3. FIND request
52
+ body = ret[2].first
53
+ body = HtmlBeautifier.beautify body
54
+ ret[2] = [body]
55
+ end
37
56
 
38
- begin
39
- request_klass = Liza.const "#{request}_request"
40
- rescue NameError
41
- request_klass = NotFoundRequest
42
- end
57
+ def _prepare env
58
+ log "#{env["REQUEST_METHOD"]} #{env["REQUEST_PATH"]}"
43
59
 
44
- # 4. CALL
60
+ path = env["REQUEST_PATH"]
45
61
 
46
- request_klass.call env
47
- rescue => e
48
- request_klass = ServerErrorRequest
49
- env["LIZA_ERROR"] = e
62
+ path, _sep, format = path.lpartition "."
63
+ format = "html" if format.empty?
50
64
 
51
- request_klass.call env
52
- end
65
+ segments = Array path.split("/")[1..-1]
53
66
 
67
+ env["LIZA_PATH"] = path
68
+ env["LIZA_FORMAT"] = format
69
+ env["LIZA_SEGMENTS"] = segments
54
70
  end
71
+
55
72
  end
@@ -1,14 +1,33 @@
1
- class WebSystem
2
- class RequestPanelTest < Liza::PanelTest
1
+ class WebSystem::RequestPanelTest < Liza::PanelTest
3
2
 
4
- test :settings do
5
- assert subject_class.log_level == :normal
6
- assert subject_class.log_color == :blue
7
- end
3
+ test :settings do
4
+ assert subject_class.log_level == :normal
5
+ assert subject_class.log_color == :blue
6
+ end
7
+
8
+ #
8
9
 
9
- # test :call do
10
- # todo "write this"
11
- # end
10
+ test :_prepare do
11
+ subject = WebBox[:request]
12
+ env = {}
13
+ env["REQUEST_PATH"] = "/foo/bar/baz"
14
+ subject._prepare env
15
+ assert_equality env, {
16
+ "REQUEST_PATH"=>"/foo/bar/baz",
17
+ "LIZA_PATH"=>"/foo/bar/baz",
18
+ "LIZA_FORMAT"=>"html",
19
+ "LIZA_SEGMENTS"=>["foo", "bar", "baz"]
20
+ }
12
21
 
22
+ env = {}
23
+ env["REQUEST_PATH"] = "/"
24
+ subject._prepare env
25
+ assert_equality env, {
26
+ "REQUEST_PATH"=>"/",
27
+ "LIZA_PATH"=>"/",
28
+ "LIZA_FORMAT"=>"html",
29
+ "LIZA_SEGMENTS"=>[]
30
+ }
13
31
  end
32
+
14
33
  end
@@ -1,12 +1,20 @@
1
- class WebSystem
2
- class WebBox < Liza::Box
3
- has_panel :request, :requests
4
- has_controller :request, :requests
1
+ class WebSystem::WebBox < Liza::Box
5
2
 
6
- # Set up your request panel per the DSL in http://guides.lizarb.org/panels/request.html
7
- requests do
8
- # set :log_level, ENV["web.request.log_level"]
9
- end
3
+ # Set up your rack panel per the DSL in http://guides.lizarb.org/panels/rack.html
4
+ panel :rack do
5
+ # set :log_level, ENV["web.rack.log_level"]
10
6
 
7
+ set :files, App.root.join("web_files")
8
+ set :host, "localhost"
9
+ set :port, 3000
11
10
  end
11
+
12
+ # Set up your request panel per the DSL in http://guides.lizarb.org/panels/request.html
13
+ panel :request do
14
+ # set :log_level, ENV["web.request.log_level"]
15
+
16
+ end
17
+
18
+ has_controller :rack, :rack
19
+ has_controller :request, :request
12
20
  end
@@ -1,18 +1,16 @@
1
- class WebSystem
2
- class WebBoxTest < Liza::BoxTest
1
+ class WebSystem::WebBoxTest < Liza::BoxTest
3
2
 
4
- test :subject_class do
5
- assert subject_class == WebSystem::WebBox
6
- end
7
-
8
- test :settings do
9
- assert subject_class.log_level == :normal
10
- assert subject_class.log_color == :blue
11
- end
3
+ test :subject_class do
4
+ assert subject_class == WebSystem::WebBox
5
+ end
12
6
 
13
- test :panels do
14
- assert subject_class.requests.is_a? RequestPanel
15
- end
7
+ test :settings do
8
+ assert subject_class.log_level == :normal
9
+ assert subject_class.log_color == :blue
10
+ end
16
11
 
12
+ test :panels do
13
+ assert subject_class[:request].is_a? WebSystem::RequestPanel
17
14
  end
15
+
18
16
  end
data/lizarb.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Liza is a light, experimental framework primarily developed to help study the Ruby language and the Ruby ecosystem."
13
13
  spec.homepage = "http://lizarb.org"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.1.0"
15
+ spec.required_ruby_version = ">= 3.2.0"
16
16
 
17
17
  spec.metadata = {
18
18
  "homepage_uri" => "https://github.com/rubyonrails-brasil/lizarb",
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  end
30
30
  end
31
31
  spec.bindir = "exe"
32
- spec.executables = ["liza", "lizarb"]
32
+ spec.executables = ["lrb", "liza", "lizarb"]
33
33
  spec.require_paths = ["lib"]
34
34
 
35
35
  # dependencies