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
data/lib/lizarb.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "colorize"
4
+ require "json"
4
5
  require "pathname"
5
6
  require "zeitwerk"
7
+ require "lerb"
6
8
 
7
9
  require_relative "lizarb/version"
8
10
 
@@ -11,7 +13,8 @@ module Lizarb
11
13
 
12
14
  #
13
15
 
14
- GEM_DIR = Gem::Specification.find_by_name("lizarb").gem_dir
16
+ SPEC = Gem::Specification.find_by_name("lizarb")
17
+ GEM_DIR = SPEC.gem_dir
15
18
  CUR_DIR = Dir.pwd
16
19
 
17
20
  IS_APP_DIR = File.file? "#{CUR_DIR}/app.rb"
@@ -36,7 +39,10 @@ module Lizarb
36
39
 
37
40
  require "#{APP_DIR}/app"
38
41
 
39
- VERSION
42
+ versions = {ruby: RUBY_VERSION, bundler: Bundler::VERSION, zeitwerk: Zeitwerk::VERSION, lizarb: VERSION}
43
+ bugs = SPEC.metadata["bug_tracker_uri"]
44
+ puts versions.to_s.green
45
+ puts "Report bugs at #{bugs}"
40
46
  end
41
47
 
42
48
  # called from "#{APP_DIR}/app"
@@ -65,4 +71,20 @@ module Lizarb
65
71
  : "#{GEM_DIR}/exe/Gemfile"
66
72
  end
67
73
 
74
+ # threads
75
+
76
+ def thread_object_id
77
+ Thread.current.object_id
78
+ end
79
+
80
+ @thread_ids = {thread_object_id => 0}
81
+ @thread_ids_mutex = Mutex.new
82
+
83
+ def thread_id
84
+ @thread_ids[thread_object_id] ||=
85
+ @thread_ids_mutex.synchronize do
86
+ @thread_ids.count
87
+ end
88
+ end
89
+
68
90
  end
@@ -1,10 +1,10 @@
1
1
  class NetSystem
2
- class RedisAdapter < Adapter
2
+ class RedisClient < Client
3
3
 
4
4
  # https://redis.io/
5
5
  # https://github.com/redis/redis-rb
6
6
  def initialize *args
7
- args = [url: Liza.const(:net_box).adapters.get(:redis_url)] if args.empty?
7
+ args = [url: Liza.const(:net_box).clients.get(:redis_url)] if args.empty?
8
8
  log "Connecting to #{args}"
9
9
  @conn = Redis.new *args
10
10
  end
@@ -1,12 +1,12 @@
1
1
  class NetSystem
2
- class RedisAdapterTest < AdapterTest
2
+ class RedisClientTest < ClientTest
3
3
 
4
4
  def subject
5
5
  @subject ||= subject_class.new
6
6
  end
7
7
 
8
8
  test :subject_class do
9
- assert subject_class == Liza::RedisAdapter
9
+ assert subject_class == Liza::RedisClient
10
10
  end
11
11
 
12
12
  test :subject do
@@ -1,10 +1,10 @@
1
1
  class NetSystem
2
- class SqliteAdapter < Adapter
2
+ class SqliteClient < Client
3
3
 
4
4
  # https://www.sqlite.org/
5
5
  # https://github.com/sparklemotion/sqlite3-ruby
6
6
  def initialize *args
7
- args = [Liza.const(:net_box).adapters.get(:sqlite)] if args.empty?
7
+ args = [Liza.const(:net_box).clients.get(:sqlite)] if args.empty?
8
8
  log "Connecting to #{args}"
9
9
  @conn = SQLite3::Database.new *args
10
10
  end
@@ -1,12 +1,12 @@
1
1
  class NetSystem
2
- class SqliteAdapterTest < AdapterTest
2
+ class SqliteClientTest < ClientTest
3
3
 
4
4
  def subject
5
5
  @subject ||= subject_class.new ":memory:"
6
6
  end
7
7
 
8
8
  test :subject_class do
9
- assert subject_class == Liza::SqliteAdapter
9
+ assert subject_class == Liza::SqliteClient
10
10
  end
11
11
 
12
12
  test :subject do
@@ -0,0 +1,5 @@
1
+ class NetSystem
2
+ class Client < Liza::Controller
3
+
4
+ end
5
+ end
@@ -1,8 +1,8 @@
1
1
  class NetSystem
2
- class ModelTest < Liza::ControllerTest
2
+ class ClientTest < Liza::ControllerTest
3
3
 
4
4
  test :subject_class do
5
- assert subject_class == NetSystem::Model
5
+ assert subject_class == NetSystem::Client
6
6
  end
7
7
 
8
8
  test :settings do
@@ -1,9 +1,9 @@
1
1
  class NetSystem
2
2
  class RedisDb < Database
3
- set_adapter :redis
3
+ set_client :redis
4
4
 
5
5
  def now
6
- array = adapter.now
6
+ array = client.now
7
7
  Time.at array[0]
8
8
  end
9
9
 
@@ -6,7 +6,7 @@ class NetSystem
6
6
  end
7
7
 
8
8
  test :subject do
9
- assert subject.adapter.class == NetSystem::RedisAdapter
9
+ assert subject.client.class == NetSystem::RedisClient
10
10
  end
11
11
 
12
12
  test :now do
@@ -1,9 +1,9 @@
1
1
  class NetSystem
2
2
  class SqliteDb < Database
3
- set_adapter :sqlite
3
+ set_client :sqlite
4
4
 
5
5
  def now
6
- array = adapter.now
6
+ array = client.now
7
7
  Time.parse array[1][0]
8
8
  end
9
9
 
@@ -6,7 +6,7 @@ class NetSystem
6
6
  end
7
7
 
8
8
  test :subject do
9
- assert subject.adapter.class == NetSystem::SqliteAdapter
9
+ assert subject.client.class == NetSystem::SqliteClient
10
10
  end
11
11
 
12
12
  test :now do
@@ -9,14 +9,14 @@ class NetSystem
9
9
  raise "please rename #{sub.name} to #{sub.name}Db"
10
10
  end
11
11
 
12
- attr_reader :adapter
12
+ attr_reader :client
13
13
 
14
- def initialize adapter: get(:adapter).new
15
- @adapter = adapter
14
+ def initialize client: get(:client).new
15
+ @client = client
16
16
  end
17
17
 
18
- def self.set_adapter adapter_id
19
- set :adapter, Liza.const("#{adapter_id}_adapter")
18
+ def self.set_client client_id
19
+ set :client, Liza.const("#{client_id}_client")
20
20
  end
21
21
 
22
22
  def self.current
@@ -27,7 +27,7 @@ class NetSystem
27
27
  end
28
28
 
29
29
  def self.call(...); current.call(...); end
30
- def call(...); @adapter.call(...); end
30
+ def call(...); @client.call(...); end
31
31
 
32
32
  end
33
33
  end
@@ -0,0 +1,31 @@
1
+ class NetSystem
2
+ class Record < Liza::Controller
3
+
4
+ def self.inherited sub
5
+ super
6
+
7
+ return if sub.name.nil?
8
+ return if sub.name.end_with? "Record"
9
+ raise "please rename #{sub.name} to #{sub.name}Record"
10
+ end
11
+
12
+ def self.db database_id = nil
13
+ if database_id.nil?
14
+ db = get :db
15
+ if db
16
+ Liza.const(:NetBox).databases.get db
17
+ else
18
+ raise "please set a db to record #{self}"
19
+ end
20
+ else
21
+ valid = Liza.const(:NetBox).databases.settings.keys
22
+ if valid.include? database_id
23
+ set :db, database_id
24
+ else
25
+ raise "invalid db `#{database_id}`, valid options are #{valid}"
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -1,8 +1,8 @@
1
1
  class NetSystem
2
- class AdapterTest < Liza::ControllerTest
2
+ class RecordTest < Liza::ControllerTest
3
3
 
4
4
  test :subject_class do
5
- assert subject_class == NetSystem::Adapter
5
+ assert subject_class == NetSystem::Record
6
6
  end
7
7
 
8
8
  test :settings do
@@ -1,11 +1,11 @@
1
1
  class NetSystem
2
2
  class NetBox < Liza::Box
3
- has_panel :adapter, :adapters
4
- has_controller :adapter, :adapters
3
+ has_panel :client, :clients
4
+ has_controller :client, :clients
5
5
 
6
- # Set up your adapter panel per the DSL in http://guides.lizarb.org/panels/adapter.html
7
- adapters do
8
- # set :log_level, ENV["net.adapter.log_level"]
6
+ # Set up your client panel per the DSL in http://guides.lizarb.org/panels/client.html
7
+ clients do
8
+ # set :log_level, ENV["net.client.log_level"]
9
9
  end
10
10
 
11
11
  has_panel :database, :databases
@@ -11,7 +11,7 @@ class NetSystem
11
11
  end
12
12
 
13
13
  test :panels do
14
- assert subject_class.adapters.is_a? AdapterPanel
14
+ assert subject_class.clients.is_a? ClientPanel
15
15
  assert subject_class.databases.is_a? DatabasePanel
16
16
  end
17
17
 
@@ -0,0 +1,5 @@
1
+ class NetSystem
2
+ class ClientPanel < Liza::Panel
3
+
4
+ end
5
+ end
@@ -1,8 +1,8 @@
1
1
  class NetSystem
2
- class AdapterPanelTest < Liza::PanelTest
2
+ class ClientPanelTest < Liza::PanelTest
3
3
 
4
4
  test :subject_class do
5
- assert subject_class == NetSystem::AdapterPanel
5
+ assert subject_class == NetSystem::ClientPanel
6
6
  end
7
7
 
8
8
  test :settings do
@@ -0,0 +1,26 @@
1
+ class WebSystem
2
+ class RackCommand < Liza::Command
3
+
4
+ def self.call args
5
+ log "args #{args}"
6
+
7
+ strategy = nil
8
+ host = nil
9
+ port = nil
10
+
11
+ if args.any? && !args[0].include?("=")
12
+ strategy = args.shift
13
+ end
14
+
15
+ args.each do |arg|
16
+ host = arg.split("=")[1] if arg.start_with? "h="
17
+ port = arg.split("=")[1] if arg.start_with? "p="
18
+ end
19
+
20
+ log({strategy:, host:, port:})
21
+
22
+ Liza.const(:web_box).rack.call strategy, host, port
23
+ end
24
+
25
+ end
26
+ end
@@ -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"]
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
+ Liza.const(:web_box).requests
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,41 +1,10 @@
1
1
  class WebSystem
2
2
  class WebCommand < Liza::Command
3
3
 
4
- set :files, App.root.join("web_files")
5
- set :host, "localhost"
6
- set :port, 3000
7
-
8
4
  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
5
+ log "args #{args}"
6
+ log "DEPRECATED: please use `lizarb rack` instead"
7
+ RackCommand.call args
39
8
  end
40
9
 
41
10
  end
@@ -0,0 +1,8 @@
1
+ class WebSystem
2
+ class Rack < Liza::Controller
3
+
4
+ # def self.call rack_app, host, port
5
+ # end
6
+
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ class WebSystem
2
+ class RackTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == WebSystem::Rack
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :blue
11
+ end
12
+
13
+ # test :call do
14
+ # todo "write this"
15
+ # end
16
+
17
+ end
18
+ end
@@ -10,7 +10,6 @@ class WebSystem
10
10
 
11
11
  body = "Client Error #{status} - #{env["LIZA_PATH"]}"
12
12
 
13
- log status
14
13
  [status, headers, [body]]
15
14
  end
16
15
 
@@ -10,7 +10,6 @@ class WebSystem
10
10
 
11
11
  body = "Client Error #{status} - #{env["LIZA_PATH"]}"
12
12
 
13
- log status
14
13
  [status, headers, [body]]
15
14
  end
16
15
 
@@ -12,7 +12,6 @@ class WebSystem
12
12
 
13
13
  body = "Server Error #{status} - #{e.class} - #{e.message}"
14
14
 
15
- log status
16
15
  [status, headers, [body]]
17
16
  end
18
17
 
@@ -0,0 +1,44 @@
1
+ class WebSystem
2
+ class RackPanel < Liza::Panel
3
+
4
+ def call strategy, host, port
5
+ puts
6
+ log({strategy:, host:, port:})
7
+
8
+ strategy ||= get :strategy
9
+ host ||= get :host
10
+ port ||= 3000
11
+ files ||= get :files
12
+
13
+ log({strategy:, host:, port:})
14
+
15
+ x = App.mode == :code ? "development" : "production"
16
+ ENV["RACK_ENV"] = x
17
+ rack_app = send "get_rack_app_#{x}"
18
+
19
+ rack_files = Object::Rack::Files.new files
20
+ rack_app = Object::Rack::Cascade.new [rack_files, rack_app]
21
+
22
+ # TODO: PumaRack
23
+ # handler = Liza.const(:"#{strategy}_rack")
24
+
25
+ require "rack/handler/puma"
26
+ handler = Object::Rack::Handler::Puma
27
+ handler.run rack_app, Host: host, Port: port
28
+ end
29
+
30
+ def get_rack_app_production()= Liza.const(:web_box).requests
31
+
32
+ def get_rack_app_development
33
+ Proc.new do |env|
34
+ ret = nil
35
+ App.reload do
36
+ log "reloading"
37
+ ret = get_rack_app_production.call env
38
+ end
39
+ ret
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ class WebSystem
2
+ class RackPanelTest < Liza::PanelTest
3
+
4
+ test :settings do
5
+ assert subject_class.log_level == :normal
6
+ assert subject_class.log_color == :blue
7
+ end
8
+
9
+ # test :call do
10
+ # todo "write this"
11
+ # end
12
+
13
+ end
14
+ end