lizarb 0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +13 -2
  4. data/Gemfile +22 -2
  5. data/Gemfile.lock +52 -0
  6. data/README.md +88 -12
  7. data/app/dev/benches/app_bench.rb +5 -0
  8. data/app/dev/benches/app_bench_test.rb +7 -0
  9. data/app/dev/benches/loops_bench.rb +148 -0
  10. data/app/dev/benches/loops_bench_test.rb +11 -0
  11. data/app/dev/commands/app_command.rb +5 -0
  12. data/app/dev/commands/app_command_test.rb +7 -0
  13. data/app/dev/commands/example_command.rb +57 -0
  14. data/app/dev/commands/example_command_test.rb +43 -0
  15. data/app/dev/commands/macro_child_command.rb +32 -0
  16. data/app/dev/commands/macro_child_command_test.rb +7 -0
  17. data/app/dev/commands/macro_parent_command.rb +70 -0
  18. data/app/dev/commands/macro_parent_command_test.rb +7 -0
  19. data/app/dev/commands/my_command.rb +7 -0
  20. data/app/dev/commands/my_command_test.rb +7 -0
  21. data/app/dev/commands/new_command.rb +9 -0
  22. data/app/dev/commands/new_command_test.rb +7 -0
  23. data/app/dev/generators/bench_generator.rb +67 -0
  24. data/app/dev/generators/bench_generator_test.rb +12 -0
  25. data/app/dev/generators/command_generator.rb +51 -0
  26. data/app/dev/generators/command_generator_test.rb +12 -0
  27. data/app/dev/generators/model_generator.rb +46 -0
  28. data/app/dev/generators/model_generator_test.rb +12 -0
  29. data/app/dev/generators/request_generator.rb +63 -0
  30. data/app/dev/generators/request_generator_test.rb +12 -0
  31. data/app/dev_box.rb +13 -0
  32. data/app/happy/axos/axo.rb +50 -0
  33. data/app/happy_box.rb +8 -0
  34. data/app/net/databases/redis_db.rb +5 -0
  35. data/app/net/databases/redis_db_test.rb +12 -0
  36. data/app/net/databases/sqlite_db.rb +11 -0
  37. data/app/net/databases/sqlite_db_test.rb +12 -0
  38. data/app/net/models/app_model.rb +20 -0
  39. data/app/net/models/app_model_test.rb +8 -0
  40. data/app/net/models/post_model.rb +4 -0
  41. data/app/net/models/post_model_test.rb +8 -0
  42. data/app/net/models/user_model.rb +4 -0
  43. data/app/net/models/user_model_test.rb +8 -0
  44. data/app/net_box.rb +21 -0
  45. data/app/web/requests/api_request.rb +61 -0
  46. data/app/web/requests/api_request_test.rb +31 -0
  47. data/app/web/requests/app_request.rb +5 -0
  48. data/app/web/requests/app_request_test.rb +7 -0
  49. data/app/web/requests/assets_request.rb +71 -0
  50. data/app/web/requests/assets_request_test.rb +33 -0
  51. data/app/web/requests/root_request.rb +55 -0
  52. data/app/web/requests/root_request_test.rb +31 -0
  53. data/app/web_box.rb +8 -0
  54. data/app.code.env +11 -0
  55. data/app.env +11 -0
  56. data/app.rb +17 -0
  57. data/app_new/.gitignore +4 -0
  58. data/app_new/Gemfile +31 -0
  59. data/app_new/Procfile +3 -0
  60. data/exe/Gemfile +3 -0
  61. data/exe/Gemfile.lock +13 -0
  62. data/exe/liza +3 -0
  63. data/exe/lizarb +11 -0
  64. data/lib/app.rb +200 -0
  65. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  66. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  67. data/lib/dev_system/dev/controllers/bench_test.rb +14 -0
  68. data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
  69. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  70. data/lib/dev_system/dev/controllers/command/dev_command.rb +24 -0
  71. data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
  72. data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
  73. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
  74. data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
  75. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  76. data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
  77. data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
  78. data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
  79. data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
  80. data/lib/dev_system/dev/controllers/command.rb +19 -0
  81. data/lib/dev_system/dev/controllers/command_test.rb +14 -0
  82. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  83. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  84. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  85. data/lib/dev_system/dev/controllers/generators/app_generator.rb +71 -0
  86. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  87. data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
  88. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
  89. data/lib/dev_system/dev/controllers/shell.rb +19 -0
  90. data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
  91. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
  92. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  93. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  94. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  95. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  96. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  97. data/lib/dev_system/dev/dev_box.rb +22 -0
  98. data/lib/dev_system/dev/dev_box_test.rb +19 -0
  99. data/lib/dev_system/dev/panels/command_panel.rb +10 -0
  100. data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
  101. data/lib/dev_system/dev/panels/log_panel.rb +10 -0
  102. data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
  103. data/lib/dev_system.rb +8 -0
  104. data/lib/happy_system/dev/happy_command.rb +11 -0
  105. data/lib/happy_system/happy/controllers/axo.rb +8 -0
  106. data/lib/happy_system/happy/happy_box.rb +12 -0
  107. data/lib/happy_system/happy/happy_box_test.rb +18 -0
  108. data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
  109. data/lib/{viral.rb → happy_system.rb} +7 -3
  110. data/lib/liza/base/box.rb +40 -0
  111. data/lib/liza/base/box_test.rb +12 -0
  112. data/lib/liza/base/controller.rb +27 -0
  113. data/lib/liza/base/controller_test.rb +12 -0
  114. data/lib/liza/base/panel.rb +38 -0
  115. data/lib/liza/base/panel_test.rb +16 -0
  116. data/lib/liza/meta/part.rb +19 -0
  117. data/lib/liza/meta/part_extension.rb +13 -0
  118. data/lib/liza/meta/part_test.rb +8 -0
  119. data/lib/liza/meta/system.rb +20 -0
  120. data/lib/liza/meta/system_test.rb +13 -0
  121. data/lib/liza/test/test.rb +11 -0
  122. data/lib/liza/test/test_test.rb +108 -0
  123. data/lib/liza/test_parts/test_assertions_part.rb +110 -0
  124. data/lib/liza/test_parts/test_context_part.rb +81 -0
  125. data/lib/liza/test_parts/test_dsl_part.rb +122 -0
  126. data/lib/liza/test_parts/test_subject_part.rb +24 -0
  127. data/lib/liza/unit.rb +149 -0
  128. data/lib/liza/unit_test.rb +79 -0
  129. data/lib/liza.rb +62 -0
  130. data/lib/lizarb/ruby/class.rb +17 -0
  131. data/lib/lizarb/ruby/proc.rb +12 -0
  132. data/lib/lizarb/ruby/string.rb +25 -0
  133. data/lib/lizarb/ruby/time.rb +9 -0
  134. data/lib/{viral → lizarb}/version.rb +2 -2
  135. data/lib/lizarb.rb +68 -0
  136. data/lib/net_system/dev/net_command.rb +24 -0
  137. data/lib/net_system/net/controllers/client/redis_client.rb +28 -0
  138. data/lib/net_system/net/controllers/client/redis_client_test.rb +29 -0
  139. data/lib/net_system/net/controllers/client/sqlite_client.rb +28 -0
  140. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +29 -0
  141. data/lib/net_system/net/controllers/client.rb +5 -0
  142. data/lib/net_system/net/controllers/client_test.rb +14 -0
  143. data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
  144. data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
  145. data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
  146. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
  147. data/lib/net_system/net/controllers/database.rb +33 -0
  148. data/lib/net_system/net/controllers/database_test.rb +14 -0
  149. data/lib/net_system/net/controllers/model.rb +31 -0
  150. data/lib/net_system/net/controllers/model_test.rb +14 -0
  151. data/lib/net_system/net/net_box.rb +20 -0
  152. data/lib/net_system/net/net_box_test.rb +19 -0
  153. data/lib/net_system/net/panels/client_panel.rb +5 -0
  154. data/lib/net_system/net/panels/client_panel_test.rb +18 -0
  155. data/lib/net_system/net/panels/database_panel.rb +12 -0
  156. data/lib/net_system/net/panels/database_panel_test.rb +18 -0
  157. data/lib/net_system.rb +3 -0
  158. data/lib/web_system/dev/web_command.rb +42 -0
  159. data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
  160. data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
  161. data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
  162. data/lib/web_system/web/controllers/request.rb +5 -0
  163. data/lib/web_system/web/controllers/request_test.rb +18 -0
  164. data/lib/web_system/web/panels/request_panel.rb +55 -0
  165. data/lib/web_system/web/panels/request_panel_test.rb +14 -0
  166. data/lib/web_system/web/web_box.rb +12 -0
  167. data/lib/web_system/web/web_box_test.rb +18 -0
  168. data/lib/web_system.rb +5 -0
  169. data/lizarb.gemspec +44 -0
  170. data/sig/{viral.rbs → lizarb.rbs} +1 -1
  171. data/tmp/.gitkeep +0 -0
  172. data/web_files/favicon.ico +0 -0
  173. data/web_files/favicon.svg +948 -0
  174. metadata +226 -13
  175. data/viral.gemspec +0 -45
@@ -0,0 +1,33 @@
1
+ class AssetsRequestTest < AppRequestTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == AssetsRequest
5
+ end
6
+
7
+ test :actions, :app, :js do
8
+ env = {
9
+ "LIZA_ACTION" => "app",
10
+ "LIZA_FORMAT" => "js",
11
+ }
12
+
13
+ status, headers, body = subject_class.call env
14
+
15
+ assert status == 200
16
+ assert headers["Framework"].to_s.start_with? "Liza"
17
+ assert body.first.include? "JS file has been loaded"
18
+ end
19
+
20
+ test :actions, :app, :css do
21
+ env = {
22
+ "LIZA_ACTION" => "app",
23
+ "LIZA_FORMAT" => "css",
24
+ }
25
+
26
+ status, headers, body = subject_class.call env
27
+
28
+ assert status == 200
29
+ assert headers["Framework"].to_s.start_with? "Liza"
30
+ assert body.first.include? "body {"
31
+ end
32
+
33
+ end
@@ -0,0 +1,55 @@
1
+ class RootRequest < AppRequest
2
+
3
+ # NOTE: There's a bug in this file. Can you find it?
4
+ def self.call env
5
+ action = env["LIZA_ACTION"]
6
+
7
+ #
8
+
9
+ @status = 200
10
+
11
+ @headers = {
12
+ "Framework" => "Liza #{Lizarb::VERSION}"
13
+ }
14
+
15
+ @body = ""
16
+
17
+ if action == "root"
18
+ render_action_root
19
+ else
20
+ @status = 404
21
+ render_action_not_found
22
+ end
23
+
24
+ log @status
25
+ [@status, @headers, [@body]]
26
+ rescue => e
27
+ @status = 500
28
+ @body = "#{e.class} - #{e.message}"
29
+
30
+ log @status
31
+ [@status, @headers, [@body]]
32
+ end
33
+
34
+ def self.render_action_root
35
+ h1 = "Ruby Works!"
36
+
37
+ @body = <<~CODE
38
+ <html>
39
+ <head>
40
+ <title>Ruby</title>
41
+ <link rel="stylesheet" href="/assets/app.css" />
42
+ <script type="application/javascript" src="/assets/app.js"></script>
43
+ </head>
44
+ <body>
45
+ <h1>#{h1}</h1>
46
+ </body>
47
+ </html>
48
+ CODE
49
+ end
50
+
51
+ def self.render_action_not_found
52
+ @body = "Ruby couldn't find your page!"
53
+ end
54
+
55
+ end
@@ -0,0 +1,31 @@
1
+ class RootRequestTest < AppRequestTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == RootRequest
5
+ end
6
+
7
+ test :actions, :root do
8
+ env = {
9
+ "LIZA_ACTION" => "root",
10
+ }
11
+
12
+ status, headers, body = subject_class.call env
13
+
14
+ assert status == 200
15
+ assert headers["Framework"].to_s.start_with? "Liza"
16
+ assert body.first.include? "<h1>Ruby Works"
17
+ end
18
+
19
+ test :actions, :other do
20
+ env = {
21
+ "LIZA_ACTION" => "other",
22
+ }
23
+
24
+ status, headers, body = subject_class.call env
25
+
26
+ assert status == 404
27
+ assert headers["Framework"].to_s.start_with? "Liza"
28
+ assert body.first.include? "couldn't find your page"
29
+ end
30
+
31
+ end
data/app/web_box.rb ADDED
@@ -0,0 +1,8 @@
1
+ class WebBox < Liza::WebBox
2
+
3
+ requests do
4
+ # Set up your request panel per the DSL in http://guides.lizarb.org/panels/request.html
5
+
6
+ end
7
+
8
+ end
data/app.code.env ADDED
@@ -0,0 +1,11 @@
1
+ # liza variables
2
+
3
+ # app variables
4
+
5
+ # dev variables
6
+
7
+ # happy variables
8
+
9
+ # net variables
10
+
11
+ # web variables
data/app.env ADDED
@@ -0,0 +1,11 @@
1
+ # liza variables
2
+
3
+ # app variables
4
+
5
+ # dev variables
6
+
7
+ # happy variables
8
+
9
+ # net variables
10
+
11
+ # web variables
data/app.rb ADDED
@@ -0,0 +1,17 @@
1
+ App.call ARGV do
2
+
3
+ # Systems help you organize your application's dependencies and RAM memory usage.
4
+ # Learn more: http://guides.lizarb.org/systems.html
5
+
6
+ system :dev
7
+ system :happy
8
+ system :net
9
+ system :web
10
+
11
+ # Modes help you organize your application's behavior and settings.
12
+ # Learn more: http://guides.lizarb.org/modes.html
13
+
14
+ mode :code
15
+ mode :demo
16
+
17
+ end
@@ -0,0 +1,4 @@
1
+ .gitignore/.bundle/
2
+ /tmp/
3
+ *.sqlite
4
+ *.rdb
data/app_new/Gemfile ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ ruby File.read(".ruby-version").strip
6
+
7
+ group :default do
8
+ gem "lizarb", "~> 1.0"
9
+ # gem "lizarb", github: "rubyonrails-brasil/lizarb"
10
+ end
11
+
12
+ group :dev do
13
+ # gems you only want to load if DevSystem is loaded
14
+ end
15
+
16
+ group :happy do
17
+ # gems you only want to load if HappySystem is loaded
18
+ end
19
+
20
+ group :net do
21
+ # gems you only want to load if NetSystem is loaded
22
+ gem "redis", "~> 5.0"
23
+ gem "sqlite3", "~> 1.5"
24
+ end
25
+
26
+ group :web do
27
+ # gems you only want to load if WebSystem is loaded
28
+ gem "rack", "~> 3.0"
29
+ gem "rackup", "~> 0.2.2"
30
+ gem "puma", "~> 5.6"
31
+ end
data/app_new/Procfile ADDED
@@ -0,0 +1,3 @@
1
+ # FOR HEROKU
2
+
3
+ web: LIZA_MODE=demo bundle exec liza web h=0.0.0.0 p=$PORT
data/exe/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
data/exe/Gemfile.lock ADDED
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ colorize (0.8.1)
5
+
6
+ PLATFORMS
7
+ x86_64-linux
8
+
9
+ DEPENDENCIES
10
+ colorize (~> 0.8.1)
11
+
12
+ BUNDLED WITH
13
+ 2.3.9
data/exe/liza ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load "#{__dir__}/lizarb"
data/exe/lizarb ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $VERBOSE = ENV["VERBOSE"]
4
+
5
+ $LOAD_PATH.unshift "#{Dir.pwd}/lib"
6
+
7
+ require_relative "../lib/lizarb.rb"
8
+
9
+ Lizarb.call
10
+
11
+ exit 0
data/lib/app.rb ADDED
@@ -0,0 +1,200 @@
1
+ module App
2
+ class Error < StandardError; end
3
+ class ModeNotFound < Error; end
4
+ class SystemNotFound < Error; end
5
+
6
+ #
7
+
8
+ module_function
9
+
10
+ def log s
11
+ puts s.bold
12
+ end
13
+
14
+ # called from "#{APP_DIR}/app"
15
+ def call argv, &block
16
+ instance_exec &block
17
+
18
+ setup_env
19
+ setup_bundle
20
+ setup_liza
21
+ bundle_systems_app Lizarb::APP_DIR
22
+
23
+ check_mode!
24
+
25
+ puts
26
+ ::DevBox.commands.call argv
27
+ puts
28
+ end
29
+
30
+ def root
31
+ Pathname Dir.pwd
32
+ end
33
+
34
+ def setup_env
35
+ require "dotenv"
36
+ Dotenv.load "app.#{mode}.env", "app.env"
37
+ end
38
+
39
+ def setup_bundle
40
+ require "bundler/setup"
41
+ Bundler.require :default, *@systems.keys
42
+ end
43
+
44
+ def setup_liza
45
+ require "liza"
46
+
47
+ @loaders << loader = Zeitwerk::Loader.new
48
+ loader.tag = Liza.to_s
49
+
50
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
51
+ loader.collapse "#{fname_for Liza}/**/*"
52
+ loader.push_dir "#{fname_for Liza}", namespace: Liza
53
+
54
+ loader.enable_reloading
55
+ loader.setup
56
+ end
57
+
58
+ def bundle_systems_app app_dir
59
+ @systems.keys.each do |k|
60
+ key = "#{k}_system"
61
+
62
+ require_system key
63
+ klass = Object.const_get key.camelize
64
+
65
+ @systems[k] = klass
66
+ end
67
+
68
+ @loaders << loader = Zeitwerk::Loader.new
69
+
70
+ @systems.each do |k, klass|
71
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
72
+ loader.collapse "#{fname_for klass}/**/*"
73
+ loader.push_dir "#{fname_for klass}", namespace: klass
74
+ end
75
+
76
+ # ORDER MATTERS: IGNORE, COLLAPSE, PUSH
77
+ loader.collapse "#{app_dir}/app/**/*"
78
+ loader.push_dir "#{app_dir}/app" if Dir.exist? "#{app_dir}/app"
79
+
80
+ loader.enable_reloading
81
+ loader.setup
82
+
83
+ @systems.each do |k, klass|
84
+ connect_system k, klass
85
+ end
86
+ end
87
+
88
+ # loaders
89
+
90
+ @loaders = []
91
+ @mutex = Mutex.new
92
+
93
+ def reload &block
94
+ @mutex.synchronize do
95
+ @loaders.map &:reload
96
+ yield if block_given?
97
+ end
98
+
99
+ true
100
+ end
101
+
102
+ def eager_load_all
103
+ Zeitwerk::Loader.eager_load_all
104
+ end
105
+
106
+ # mode
107
+
108
+ @modes = [:code]
109
+ ENV["LIZA_MODE"] ||= @modes.first.to_s
110
+ @mode = ENV["LIZA_MODE"].to_sym
111
+
112
+ def mode mode = nil
113
+ return @mode if mode.nil?
114
+ @modes << mode.to_sym
115
+ end
116
+
117
+ def check_mode!
118
+ return if @modes.include? @mode
119
+ raise ModeNotFound, "LIZA_MODE `#{@mode}` not found in #{@modes}", []
120
+ end
121
+
122
+ # systems
123
+
124
+ @systems = {}
125
+
126
+ def system key
127
+ raise "locked" if @locked
128
+ @systems[key] = nil
129
+ end
130
+
131
+ def systems
132
+ @systems
133
+ end
134
+
135
+ def self.require_system key
136
+ require key
137
+ rescue LoadError => e
138
+ def e.backtrace; []; end
139
+ raise SystemNotFound, "FILE #{key}.rb not found on $LOAD_PATH", []
140
+ end
141
+
142
+ # parts
143
+
144
+ def connect_part part_klass, key, system
145
+ klass = if system.nil?
146
+ Liza.const "#{key}_part"
147
+ else
148
+ Liza.const("#{system}_system")
149
+ .const "#{key}_part"
150
+ end
151
+
152
+ log "CONNECTING PART #{part_klass.to_s.rjust 25}.part :#{key}" if $VERBOSE
153
+
154
+ if klass.insertion
155
+ part_klass.class_exec &klass.insertion
156
+ end
157
+
158
+ if klass.extension
159
+ klass.const_set :Extension, Class.new(Liza::PartExtension)
160
+ klass::Extension.class_exec &klass.extension
161
+ end
162
+ end
163
+
164
+ # systems
165
+
166
+ def connect_system key, system_klass
167
+ t = Time.now
168
+
169
+ color_system_klass = system_klass.to_s.colorize system_klass.log_color
170
+ color_key = key.to_s.colorize system_klass.log_color
171
+
172
+ registrar_index = 0
173
+ system_klass.registrar.each do |string, target_block|
174
+ reg_type, _sep, reg_target = string.to_s.lpartition "_"
175
+
176
+ registrar_index += 1
177
+
178
+ target_klass = Liza.const reg_target
179
+
180
+ if reg_type == "insertion"
181
+ target_klass.class_exec &target_block
182
+ else
183
+ raise "TODO: decide and implement system extension"
184
+ end
185
+
186
+ log "CONNECTING SYSTEM PART #{color_system_klass}.#{reg_type} #{target_klass}"
187
+
188
+ end
189
+ log "CONNECTING SYSTEM - #{t.diff}s for #{color_system_klass} to connect to #{registrar_index} system parts"
190
+ end
191
+
192
+ #
193
+
194
+ def fname_for klass
195
+ # /path/to/liza.rb
196
+ # /path/to/liza
197
+ Object.const_source_location(klass.name)[0][0..-4]
198
+ end
199
+
200
+ end
@@ -0,0 +1,11 @@
1
+ class DevSystem
2
+ class Bench < Liza::Controller
3
+
4
+ # DSLS
5
+
6
+ def self.main_dsl
7
+ part :"bench_dsl_main", system: :dev
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,60 @@
1
+ class DevSystem
2
+ class BenchDslMainPart < Liza::Part
3
+
4
+ insertion do
5
+
6
+ def self.call args
7
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
8
+
9
+ # https://rubyapi.org/3.1/o/benchmark
10
+ require "benchmark"
11
+
12
+ if @setup_bl
13
+ log "Setting up..."
14
+ instance_exec &@setup_bl
15
+ log "Set up"
16
+ end
17
+
18
+ log "Benchmarking #{marks.count} Ruby Blocks"
19
+ puts
20
+
21
+ length = marks.keys.map(&:length).max
22
+
23
+ marks.each do |label, bl|
24
+ log "Benchmarking #{label}"
25
+ marks[label] = Benchmark.measure label, &bl
26
+ end
27
+
28
+ puts
29
+
30
+ log "#{"Reporting".ljust_blanks(length + 17)} App CPU Time Kernel CPU Time Total CPU Time"
31
+ puts
32
+
33
+ sorted = marks.sort_by { |_k, tms| tms.total }.to_h
34
+
35
+ sorted.each.with_index do |(label, tms), i|
36
+ tms = tms.format "%10.6u %10.6y %10.6t"
37
+ s = "[#{i.next.to_s.rjust_zeroes 2}/#{marks.count.to_s.rjust_zeroes 2}] #{label.rjust_blanks length} #{tms}"
38
+
39
+ s = s.green if i == 0
40
+ s = s.red if i == marks.count-1
41
+ log s
42
+ end
43
+ puts
44
+ log "Done"
45
+ end
46
+
47
+ #
48
+
49
+ def self.marks()= @marks ||= {}
50
+
51
+ def self.mark(label, &block)= marks[label] = block
52
+
53
+ def self.setup &block
54
+ @setup_bl = block if block_given?
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class BenchTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::Bench
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,24 @@
1
+ class DevSystem
2
+ class BenchCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "args: #{args}"
8
+ puts
9
+
10
+ # 2. FIND bench
11
+
12
+ bench = args[0]
13
+
14
+ log({bench:})
15
+
16
+ bench_klass = Liza.const "#{bench}_bench"
17
+
18
+ # 3. CALL
19
+
20
+ bench_klass.call args[1..-1]
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class BenchCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::BenchCommand
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,24 @@
1
+ class DevSystem
2
+ class DevCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "args: #{args}"
8
+ puts
9
+
10
+ # 2. FIND terminal
11
+
12
+ terminal = args[0] || "irb"
13
+
14
+ log({terminal:})
15
+
16
+ terminal_klass = Liza.const "#{terminal}_terminal"
17
+
18
+ # 3. CALL
19
+
20
+ terminal_klass.call Array(args[1..-1])
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class DevCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::DevCommand
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,11 @@
1
+ class DevSystem
2
+ class EchoCommand < Command
3
+
4
+ def self.call args
5
+ log :higher, "Called #{self} with args #{args}"
6
+
7
+ raise RuntimeError, args.to_s
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class EchoCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::EchoCommand
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,23 @@
1
+ class DevSystem
2
+ class GenerateCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "args: #{args}"
8
+ puts
9
+
10
+ # 2. FIND generator
11
+
12
+ generator = args[0]
13
+
14
+ log({generator:})
15
+
16
+ generator_klass = Liza.const "#{generator}_generator"
17
+
18
+ # 3. CALL
19
+
20
+ generator_klass.call args[1..-1]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class GenerateCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::GenerateCommand
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