lizarb 0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/CHANGELOG.md +13 -2
  4. data/Gemfile +21 -2
  5. data/Gemfile.lock +44 -0
  6. data/README.md +88 -12
  7. data/app/dev/commands/app_command.rb +5 -0
  8. data/app/dev/commands/app_command_test.rb +7 -0
  9. data/app/dev/commands/example_command.rb +57 -0
  10. data/app/dev/commands/example_command_test.rb +43 -0
  11. data/app/dev/commands/macro_child_command.rb +32 -0
  12. data/app/dev/commands/macro_child_command_test.rb +7 -0
  13. data/app/dev/commands/macro_parent_command.rb +70 -0
  14. data/app/dev/commands/macro_parent_command_test.rb +7 -0
  15. data/app/dev/commands/my_command.rb +7 -0
  16. data/app/dev/commands/my_command_test.rb +7 -0
  17. data/app/dev/commands/new_command.rb +69 -0
  18. data/app/dev/commands/new_command_test.rb +7 -0
  19. data/app/dev_box.rb +13 -0
  20. data/app/happy/axos/axo.rb +50 -0
  21. data/app/happy_box.rb +8 -0
  22. data/app/net/databases/redis_db.rb +5 -0
  23. data/app/net/databases/redis_db_test.rb +12 -0
  24. data/app/net/databases/sqlite_db.rb +11 -0
  25. data/app/net/databases/sqlite_db_test.rb +12 -0
  26. data/app/net/models/app_model.rb +20 -0
  27. data/app/net/models/app_model_test.rb +8 -0
  28. data/app/net/models/post_model.rb +4 -0
  29. data/app/net/models/post_model_test.rb +8 -0
  30. data/app/net/models/user_model.rb +4 -0
  31. data/app/net/models/user_model_test.rb +8 -0
  32. data/app/net_box.rb +21 -0
  33. data/app/web/requests/api_request.rb +61 -0
  34. data/app/web/requests/api_request_test.rb +31 -0
  35. data/app/web/requests/app_request.rb +5 -0
  36. data/app/web/requests/app_request_test.rb +7 -0
  37. data/app/web/requests/assets_request.rb +71 -0
  38. data/app/web/requests/assets_request_test.rb +33 -0
  39. data/app/web/requests/root_request.rb +55 -0
  40. data/app/web/requests/root_request_test.rb +31 -0
  41. data/app/web_box.rb +8 -0
  42. data/app.code.env +11 -0
  43. data/app.env +11 -0
  44. data/app.rb +17 -0
  45. data/app_new/.gitignore +4 -0
  46. data/app_new/Gemfile +31 -0
  47. data/app_new/Procfile +3 -0
  48. data/exe/Gemfile +3 -0
  49. data/exe/Gemfile.lock +13 -0
  50. data/exe/liza +3 -0
  51. data/exe/lizarb +11 -0
  52. data/lib/app.rb +200 -0
  53. data/lib/dev_system/dev/controllers/command/dev_command.rb +19 -0
  54. data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
  55. data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
  56. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
  57. data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
  58. data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
  59. data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
  60. data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
  61. data/lib/dev_system/dev/controllers/command.rb +19 -0
  62. data/lib/dev_system/dev/controllers/command_test.rb +14 -0
  63. data/lib/dev_system/dev/dev_box.rb +19 -0
  64. data/lib/dev_system/dev/dev_box_test.rb +19 -0
  65. data/lib/dev_system/dev/panels/command_panel.rb +10 -0
  66. data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
  67. data/lib/dev_system/dev/panels/log_panel.rb +10 -0
  68. data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
  69. data/lib/dev_system.rb +8 -0
  70. data/lib/happy_system/dev/happy_command.rb +11 -0
  71. data/lib/happy_system/happy/controllers/axo.rb +8 -0
  72. data/lib/happy_system/happy/happy_box.rb +12 -0
  73. data/lib/happy_system/happy/happy_box_test.rb +18 -0
  74. data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
  75. data/lib/{viral.rb → happy_system.rb} +7 -3
  76. data/lib/liza/base/box.rb +40 -0
  77. data/lib/liza/base/box_test.rb +12 -0
  78. data/lib/liza/base/controller.rb +27 -0
  79. data/lib/liza/base/controller_test.rb +12 -0
  80. data/lib/liza/base/panel.rb +38 -0
  81. data/lib/liza/base/panel_test.rb +16 -0
  82. data/lib/liza/meta/part.rb +19 -0
  83. data/lib/liza/meta/part_extension.rb +13 -0
  84. data/lib/liza/meta/part_test.rb +8 -0
  85. data/lib/liza/meta/system.rb +20 -0
  86. data/lib/liza/meta/system_test.rb +13 -0
  87. data/lib/liza/test/test.rb +11 -0
  88. data/lib/liza/test/test_test.rb +108 -0
  89. data/lib/liza/test_parts/test_assertions_part.rb +110 -0
  90. data/lib/liza/test_parts/test_context_part.rb +81 -0
  91. data/lib/liza/test_parts/test_dsl_part.rb +122 -0
  92. data/lib/liza/test_parts/test_subject_part.rb +19 -0
  93. data/lib/liza/unit.rb +149 -0
  94. data/lib/liza/unit_test.rb +79 -0
  95. data/lib/liza.rb +34 -0
  96. data/lib/lizarb/ruby/class.rb +15 -0
  97. data/lib/lizarb/ruby/string.rb +9 -0
  98. data/lib/lizarb/ruby/time.rb +9 -0
  99. data/lib/{viral → lizarb}/version.rb +2 -2
  100. data/lib/lizarb.rb +68 -0
  101. data/lib/net_system/dev/net_command.rb +24 -0
  102. data/lib/net_system/net/controllers/adapter/redis_adapter.rb +28 -0
  103. data/lib/net_system/net/controllers/adapter/redis_adapter_test.rb +29 -0
  104. data/lib/net_system/net/controllers/adapter/sqlite_adapter.rb +28 -0
  105. data/lib/net_system/net/controllers/adapter/sqlite_adapter_test.rb +29 -0
  106. data/lib/net_system/net/controllers/adapter.rb +5 -0
  107. data/lib/net_system/net/controllers/adapter_test.rb +14 -0
  108. data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
  109. data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
  110. data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
  111. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
  112. data/lib/net_system/net/controllers/database.rb +33 -0
  113. data/lib/net_system/net/controllers/database_test.rb +14 -0
  114. data/lib/net_system/net/controllers/model.rb +31 -0
  115. data/lib/net_system/net/controllers/model_test.rb +14 -0
  116. data/lib/net_system/net/net_box.rb +20 -0
  117. data/lib/net_system/net/net_box_test.rb +19 -0
  118. data/lib/net_system/net/panels/adapter_panel.rb +5 -0
  119. data/lib/net_system/net/panels/adapter_panel_test.rb +18 -0
  120. data/lib/net_system/net/panels/database_panel.rb +12 -0
  121. data/lib/net_system/net/panels/database_panel_test.rb +18 -0
  122. data/lib/net_system.rb +3 -0
  123. data/lib/web_system/dev/web_command.rb +42 -0
  124. data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
  125. data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
  126. data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
  127. data/lib/web_system/web/controllers/request.rb +5 -0
  128. data/lib/web_system/web/controllers/request_test.rb +18 -0
  129. data/lib/web_system/web/panels/request_panel.rb +55 -0
  130. data/lib/web_system/web/panels/request_panel_test.rb +14 -0
  131. data/lib/web_system/web/web_box.rb +12 -0
  132. data/lib/web_system/web/web_box_test.rb +18 -0
  133. data/lib/web_system.rb +5 -0
  134. data/lizarb.gemspec +44 -0
  135. data/sig/{viral.rbs → lizarb.rbs} +1 -1
  136. data/web_files/favicon.ico +0 -0
  137. data/web_files/favicon.svg +948 -0
  138. metadata +190 -13
  139. data/viral.gemspec +0 -45
@@ -0,0 +1,12 @@
1
+ class SqliteDbTest < Liza::SqliteDbTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == SqliteDb
5
+ assert SqliteDb.current.class == SqliteDb
6
+ assert Liza::SqliteDb.current.class == SqliteDb
7
+ assert SqliteDb.current == Liza::SqliteDb.current
8
+ assert SqliteDb.current.adapter == Liza::SqliteDb.current.adapter
9
+ assert SqliteDb.current.adapter.conn == Liza::SqliteDb.current.adapter.conn
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ class AppModel < Liza::Model
2
+ db :sqlite
3
+
4
+ def self.create_tables!
5
+ db.call <<-SQLITE
6
+ CREATE TABLE #{get :table} (
7
+ id integer,
8
+ name text,
9
+ text text
10
+ );
11
+ SQLITE
12
+ end
13
+
14
+ def self.drop_tables!
15
+ db.call <<-SQLITE
16
+ DROP TABLE #{get :table};
17
+ SQLITE
18
+ end
19
+
20
+ end
@@ -0,0 +1,8 @@
1
+ class AppModelTest < Liza::ModelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == AppModel
5
+ assert subject_class.db == SqliteDb.current
6
+ end
7
+
8
+ end
@@ -0,0 +1,4 @@
1
+ class PostModel < AppModel
2
+ set :table, :posts
3
+
4
+ end
@@ -0,0 +1,8 @@
1
+ class PostModelTest < Liza::ModelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == PostModel
5
+ assert subject_class.db == SqliteDb.current
6
+ end
7
+
8
+ end
@@ -0,0 +1,4 @@
1
+ class UserModel < AppModel
2
+ set :table, :users
3
+
4
+ end
@@ -0,0 +1,8 @@
1
+ class UserModelTest < Liza::ModelTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == UserModel
5
+ assert subject_class.db == SqliteDb.current
6
+ end
7
+
8
+ end
data/app/net_box.rb ADDED
@@ -0,0 +1,21 @@
1
+ class NetBox < Liza::NetBox
2
+
3
+ adapters do
4
+ # Set up your adapter panel per the DSL in http://guides.lizarb.org/panels/adapter.html
5
+
6
+ set :redis_url, "redis://localhost:6379/15"
7
+ set :sqlite, "tmp/app.#{Time.now.to_i}.sqlite" if App.mode == :code
8
+ set :sqlite, "app.#{App.mode}.sqlite"
9
+
10
+ end
11
+
12
+ databases do
13
+ # Set up your database panel per the DSL in http://guides.lizarb.org/panels/database.html
14
+
15
+ define :redis, RedisDb.current
16
+ define :sql, SqliteDb.current
17
+ define :sqlite, SqliteDb.current
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,61 @@
1
+ class ApiRequest < AppRequest
2
+
3
+ def self.call env
4
+ path = env["REQUEST_PATH"]
5
+
6
+ #
7
+
8
+ status = 200
9
+ headers = {
10
+ "Framework" => "Liza #{Lizarb::VERSION}"
11
+ }
12
+ body = ""
13
+
14
+ #
15
+
16
+ segments = Array path.split("/")[1..-1]
17
+
18
+ case segments
19
+ in "api", "auth", "sign_up"
20
+ body = render_route_api_auth_sign_up
21
+ in "api", "auth", "sign_in"
22
+ body = render_route_api_auth_sign_in
23
+ in "api", "auth", "account"
24
+ body = render_route_api_auth_account
25
+ in "api", "auth", "sign_out"
26
+ body = render_route_api_auth_sign_out
27
+ in "api", "users"
28
+ body = render_route_api_users
29
+ else
30
+ status = 404
31
+ body = render_route_not_found env["LIZA_PATH"]
32
+ end
33
+
34
+ log status
35
+ [status, headers, [body]]
36
+ end
37
+
38
+ def self.render_route_api_auth_sign_up
39
+ "route: render_route_api_auth_sign_up"
40
+ end
41
+
42
+ def self.render_route_api_auth_sign_in
43
+ "route: render_route_api_auth_sign_in"
44
+ end
45
+
46
+ def self.render_route_api_auth_account
47
+ "route: render_route_api_auth_account"
48
+ end
49
+
50
+ def self.render_route_api_auth_sign_out
51
+ "route: render_route_api_auth_sign_out"
52
+ end
53
+
54
+ def self.render_route_api_users
55
+ "route: render_route_api_users"
56
+ end
57
+
58
+ def self.render_route_not_found path
59
+ "route: render_route_not_found #{path}"
60
+ end
61
+ end
@@ -0,0 +1,31 @@
1
+ class ApiRequestTest < AppRequestTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == ApiRequest
5
+ end
6
+
7
+ test :actions, :root do
8
+ env = {
9
+ "REQUEST_PATH" => "/",
10
+ }
11
+
12
+ status, headers, body = subject_class.call env
13
+
14
+ assert status == 404
15
+ assert headers["Framework"].to_s.start_with? "Liza"
16
+ assert body.first.include? "render_route_not_found"
17
+ end
18
+
19
+ test :actions, :sign_up do
20
+ env = {
21
+ "REQUEST_PATH" => "/api/auth/sign_up",
22
+ }
23
+
24
+ status, headers, body = subject_class.call env
25
+
26
+ assert status == 200
27
+ assert headers["Framework"].to_s.start_with? "Liza"
28
+ assert body.first.include? "render_route_api_auth_sign_up"
29
+ end
30
+
31
+ end
@@ -0,0 +1,5 @@
1
+ # Set up your request controllers per the DSL in http://guides.lizarb.org/controllers/request.html
2
+
3
+ class AppRequest < Liza::Request
4
+
5
+ end
@@ -0,0 +1,7 @@
1
+ class AppRequestTest < Liza::RequestTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == AppRequest
5
+ end
6
+
7
+ end
@@ -0,0 +1,71 @@
1
+ class AssetsRequest < AppRequest
2
+
3
+ def self.call env
4
+ new.call env
5
+ end
6
+
7
+ def call env
8
+ action = env["LIZA_ACTION"].to_sym
9
+ format = env["LIZA_FORMAT"].to_sym
10
+
11
+ #
12
+
13
+ @status = 200
14
+ @headers = {
15
+ "Framework" => "Liza #{Lizarb::VERSION}"
16
+ }
17
+ @body = ""
18
+
19
+ render_action_admin_format_js if action == :admin && format == :js
20
+ render_action_admin_format_css if action == :admin && format == :css
21
+ render_action_app_format_js if action == :app && format == :js
22
+ render_action_app_format_css if action == :app && format == :css
23
+
24
+ log @status
25
+ [@status, @headers, [@body]]
26
+ end
27
+
28
+ # helper methods
29
+
30
+ def render_action_admin_format_js
31
+ @body = "alert('it works')"
32
+ end
33
+
34
+ def render_action_admin_format_css
35
+ @body = "body { background: gray }"
36
+ end
37
+
38
+ def render_action_app_format_js
39
+ @body = <<-CODE
40
+ window.onload = () => {
41
+ var h1 = document.createElement("h1");
42
+ h1.setAttribute("style", "color: white");
43
+ h1.innerHTML="JS file has been loaded. Random String: #{random_string}";
44
+ document.body.append(h1);
45
+ }
46
+ CODE
47
+ end
48
+
49
+ def render_action_app_format_css
50
+ @body = <<-CODE
51
+ body {
52
+ background: ##{random_color};
53
+ font-family: Roboto;
54
+ }
55
+ CODE
56
+ end
57
+
58
+ def random_string
59
+ Array("A".."z").sample(16).join
60
+ end
61
+
62
+ def random_color
63
+ s = ""
64
+ 3.times do |i|
65
+ s += Array(3..9).sample.to_s(16)
66
+ s += "0"
67
+ end
68
+ s
69
+ end
70
+
71
+ end
@@ -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