lizarb 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +7 -4
- data/README.md +23 -64
- data/README_SYSTEMS.md +80 -0
- data/Rakefile +3 -1
- data/app/dev/benches/loops_bench.rb +35 -0
- data/app/dev/commands/calculator_command.rb +69 -0
- data/app/dev/commands/calculator_command_test.rb +58 -0
- data/app/dev/commands/circle_command.rb +70 -0
- data/app/dev/commands/circle_command_test.rb +76 -0
- data/app/dev/commands/narrative_method_command.rb +60 -0
- data/app/dev/commands/narrative_method_command_test.rb +36 -0
- data/app/dev/commands/quadratic_command.rb +66 -0
- data/app/dev/commands/quadratic_command_test.rb +47 -0
- data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
- data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
- data/app/dev/generators/bench_generator.rb +2 -51
- data/app/dev/generators/command_generator/command.rb.erb +26 -0
- data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
- data/app/dev/generators/command_generator.rb +2 -35
- data/app/dev/generators/record_generator.rb +46 -0
- data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
- data/app/dev_box.rb +24 -4
- data/app/happy_box.rb +1 -1
- data/app/net/databases/sqlite_db_test.rb +5 -5
- data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
- data/app/net/records/app_record_test.rb +8 -0
- data/app/net/records/post_record.rb +4 -0
- data/app/net/records/post_record_test.rb +8 -0
- data/app/net/records/user_record.rb +4 -0
- data/app/net/records/user_record_test.rb +8 -0
- data/app/net_box.rb +7 -7
- data/app/web/requests/api_request.rb +8 -7
- data/app/web/requests/assets_request.rb +12 -13
- data/app/web/requests/root_request.rb +6 -7
- data/app/web/requests/root_request_test.rb +1 -1
- data/app/web_box.rb +9 -1
- data/exe/lrb +3 -0
- data/lib/app.rb +19 -15
- data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +27 -0
- data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench/not_found_bench_test.rb} +3 -5
- data/lib/dev_system/dev/controllers/bench.rb +5 -7
- data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +37 -39
- data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command/bench_command.rb +20 -12
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command/echo_command.rb +5 -7
- data/lib/dev_system/dev/controllers/command/echo_command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command/generate_command.rb +22 -12
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command/not_found_command.rb +27 -0
- data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +12 -0
- data/lib/dev_system/dev/controllers/command/terminal_command.rb +22 -0
- data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +12 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +64 -49
- data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command/version_command.rb +4 -6
- data/lib/dev_system/dev/controllers/command/version_command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/command.rb +11 -13
- data/lib/dev_system/dev/controllers/command_test.rb +8 -10
- data/lib/dev_system/dev/controllers/generator.rb +5 -7
- data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +35 -37
- data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +122 -47
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +8 -10
- data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
- data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -0
- data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +12 -0
- data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
- data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
- data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
- data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
- data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
- data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
- data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
- data/lib/dev_system/dev/controllers/shell.rb +26 -14
- data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
- data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +11 -13
- data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
- data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
- data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
- data/lib/dev_system/dev/controllers/terminal.rb +11 -13
- data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
- data/lib/dev_system/dev/dev_box.rb +33 -16
- data/lib/dev_system/dev/dev_box_test.rb +12 -14
- data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
- data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
- data/lib/dev_system/dev/panels/command_panel.rb +24 -6
- data/lib/dev_system/dev/panels/command_panel_test.rb +15 -17
- data/lib/dev_system/dev/panels/generator_panel.rb +3 -0
- data/lib/dev_system/dev/panels/generator_panel_test.rb +12 -0
- data/lib/dev_system/dev/panels/log_panel.rb +9 -6
- data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
- data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
- data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
- data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
- data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
- data/lib/happy_system/happy/controllers/axo.rb +4 -5
- data/lib/happy_system/happy/happy_box.rb +6 -9
- data/lib/happy_system/happy/happy_box_test.rb +11 -13
- data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
- data/lib/lerb.rb +106 -0
- data/lib/liza/base/box.rb +71 -26
- data/lib/liza/base/box_test.rb +7 -9
- data/lib/liza/base/controller.rb +19 -19
- data/lib/liza/base/controller_test.rb +7 -9
- data/lib/liza/base/panel.rb +40 -24
- data/lib/liza/base/panel_test.rb +10 -12
- data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
- data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
- data/lib/liza/meta/part.rb +12 -14
- data/lib/liza/meta/part_extension.rb +14 -11
- data/lib/liza/meta/part_test.rb +4 -6
- data/lib/liza/meta/system.rb +12 -14
- data/lib/liza/meta/system_test.rb +8 -10
- data/lib/liza/ruby_test.rb +7 -0
- data/lib/liza/ruby_tests/module_test.rb +21 -0
- data/lib/liza/ruby_tests/string_test.rb +59 -0
- data/lib/liza/test/test.rb +7 -8
- data/lib/liza/test/test_test.rb +168 -76
- data/lib/liza/test_parts/test_assertions_advanced_part.rb +125 -0
- data/lib/liza/test_parts/test_assertions_part.rb +81 -82
- data/lib/liza/test_parts/test_dsl_part.rb +44 -98
- data/lib/liza/test_parts/test_log_part.rb +122 -0
- data/lib/liza/test_parts/test_subject_part.rb +16 -18
- data/lib/liza/test_parts/test_tree_part.rb +137 -0
- data/lib/liza/unit.rb +108 -102
- data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
- data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
- data/lib/liza/unit_test.rb +69 -71
- data/lib/liza.rb +5 -0
- data/lib/lizarb/ruby/module.rb +17 -0
- data/lib/lizarb/ruby/string.rb +10 -2
- data/lib/lizarb/version.rb +1 -1
- data/lib/lizarb.rb +24 -2
- data/lib/net_system/dev/net_command.rb +10 -12
- data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
- data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
- data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
- data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
- data/lib/net_system/net/controllers/client.rb +1 -3
- data/lib/net_system/net/controllers/client_test.rb +8 -10
- data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
- data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
- data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
- data/lib/net_system/net/controllers/database.rb +21 -23
- data/lib/net_system/net/controllers/database_test.rb +8 -10
- data/lib/net_system/net/controllers/record.rb +29 -0
- data/lib/net_system/net/controllers/record_test.rb +12 -0
- data/lib/net_system/net/net_box.rb +11 -16
- data/lib/net_system/net/net_box_test.rb +12 -14
- data/lib/net_system/net/panels/client_panel.rb +1 -3
- data/lib/net_system/net/panels/client_panel_test.rb +11 -13
- data/lib/net_system/net/panels/database_panel.rb +6 -8
- data/lib/net_system/net/panels/database_panel_test.rb +11 -13
- data/lib/web_system/dev/rack_command.rb +35 -0
- data/lib/web_system/dev/request_command.rb +143 -0
- data/lib/web_system/dev/web_command.rb +6 -39
- data/lib/web_system/web/controllers/rack.rb +6 -0
- data/lib/web_system/web/controllers/rack_test.rb +16 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +9 -12
- data/lib/web_system/web/controllers/request/not_found_request.rb +9 -12
- data/lib/web_system/web/controllers/request/server_error_request.rb +10 -13
- data/lib/web_system/web/controllers/request.rb +1 -3
- data/lib/web_system/web/controllers/request_test.rb +11 -13
- data/lib/web_system/web/panels/rack_panel.rb +42 -0
- data/lib/web_system/web/panels/rack_panel_test.rb +12 -0
- data/lib/web_system/web/panels/request_panel.rb +54 -37
- data/lib/web_system/web/panels/request_panel_test.rb +28 -9
- data/lib/web_system/web/web_box.rb +16 -8
- data/lib/web_system/web/web_box_test.rb +11 -13
- data/lizarb.gemspec +2 -2
- metadata +76 -28
- data/app/dev/commands/example_command.rb +0 -57
- data/app/dev/commands/example_command_test.rb +0 -43
- data/app/dev/commands/macro_child_command.rb +0 -32
- data/app/dev/commands/macro_child_command_test.rb +0 -7
- data/app/dev/commands/macro_parent_command.rb +0 -70
- data/app/dev/commands/macro_parent_command_test.rb +0 -7
- data/app/dev/commands/my_command.rb +0 -7
- data/app/dev/commands/my_command_test.rb +0 -7
- data/app/dev/generators/model_generator.rb +0 -46
- data/app/net/models/app_model_test.rb +0 -8
- data/app/net/models/post_model.rb +0 -4
- data/app/net/models/post_model_test.rb +0 -8
- data/app/net/models/user_model.rb +0 -4
- data/app/net/models/user_model_test.rb +0 -8
- data/app_new/.gitignore +0 -4
- data/app_new/Gemfile +0 -31
- data/app_new/Procfile +0 -3
- data/lib/dev_system/dev/controllers/command/dev_command.rb +0 -24
- data/lib/liza/test_parts/test_context_part.rb +0 -81
- data/lib/net_system/net/controllers/model.rb +0 -31
- 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,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
|
-
|
5
|
-
|
3
|
+
def self.call env
|
4
|
+
status = 400
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
headers = {
|
7
|
+
"Framework" => "Liza #{Lizarb::VERSION}"
|
8
|
+
}
|
10
9
|
|
11
|
-
|
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
|
-
|
5
|
-
|
3
|
+
def self.call env
|
4
|
+
status = 404
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
headers = {
|
7
|
+
"Framework" => "Liza #{Lizarb::VERSION}"
|
8
|
+
}
|
10
9
|
|
11
|
-
|
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
|
-
|
5
|
-
|
3
|
+
def self.call env
|
4
|
+
status = 500
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
headers = {
|
7
|
+
"Framework" => "Liza #{Lizarb::VERSION}"
|
8
|
+
}
|
10
9
|
|
11
|
-
|
10
|
+
e = env["LIZA_ERROR"]
|
12
11
|
|
13
|
-
|
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,18 +1,16 @@
|
|
1
|
-
class WebSystem
|
2
|
-
class RequestTest < Liza::ControllerTest
|
1
|
+
class WebSystem::RequestTest < Liza::ControllerTest
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == WebSystem::Request
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :blue
|
10
|
+
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
@@ -1,55 +1,72 @@
|
|
1
|
-
class WebSystem
|
2
|
-
|
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
|
-
|
5
|
-
puts
|
20
|
+
#
|
6
21
|
|
7
|
-
|
22
|
+
def find env
|
23
|
+
_prepare env
|
8
24
|
|
9
|
-
|
25
|
+
path = env["LIZA_PATH"]
|
10
26
|
|
11
|
-
|
27
|
+
segments = env["LIZA_SEGMENTS"].dup
|
28
|
+
request = segments.shift || "root"
|
29
|
+
action = segments.shift || "index"
|
12
30
|
|
13
|
-
|
31
|
+
env["LIZA_REQUEST"] = request
|
32
|
+
env["LIZA_ACTION"] = action
|
33
|
+
format = env["LIZA_FORMAT"]
|
14
34
|
|
15
|
-
|
16
|
-
format = "html" if format.empty?
|
35
|
+
log({request:, action:, format:})
|
17
36
|
|
18
|
-
|
37
|
+
env["LIZA_REQUEST_CLASS"] = _find_request_class request
|
38
|
+
end
|
19
39
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
30
|
-
env["LIZA_REQUEST"] = request
|
31
|
-
env["LIZA_ACTION"] = action
|
32
|
-
env["LIZA_FORMAT"] = format
|
46
|
+
#
|
33
47
|
|
34
|
-
|
48
|
+
def _html_beautify env, ret
|
49
|
+
return unless defined? HtmlBeautifier
|
50
|
+
return unless env["LIZA_FORMAT"] == "html"
|
35
51
|
|
36
|
-
|
52
|
+
body = ret[2].first
|
53
|
+
body = HtmlBeautifier.beautify body
|
54
|
+
ret[2] = [body]
|
55
|
+
end
|
37
56
|
|
38
|
-
|
39
|
-
|
40
|
-
rescue NameError
|
41
|
-
request_klass = NotFoundRequest
|
42
|
-
end
|
57
|
+
def _prepare env
|
58
|
+
log "#{env["REQUEST_METHOD"]} #{env["REQUEST_PATH"]}"
|
43
59
|
|
44
|
-
|
60
|
+
path = env["REQUEST_PATH"]
|
45
61
|
|
46
|
-
|
47
|
-
|
48
|
-
request_klass = ServerErrorRequest
|
49
|
-
env["LIZA_ERROR"] = e
|
62
|
+
path, _sep, format = path.lpartition "."
|
63
|
+
format = "html" if format.empty?
|
50
64
|
|
51
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
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.
|
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
|