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
data/lib/liza/unit.rb
CHANGED
@@ -1,149 +1,155 @@
|
|
1
|
-
|
2
|
-
class Unit
|
1
|
+
class Liza::Unit
|
3
2
|
|
4
|
-
|
3
|
+
# PARTS
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def self.part key, system: nil
|
6
|
+
App.connect_part self, key, system
|
7
|
+
end
|
9
8
|
|
10
|
-
|
9
|
+
def self.const_missing name
|
10
|
+
Liza.const name
|
11
|
+
rescue Liza::ConstNotFound => e
|
12
|
+
raise NameError, "uninitialized constant #{name}", caller[1..], cause: nil
|
13
|
+
end
|
11
14
|
|
12
|
-
|
13
|
-
@settings ||= {}
|
14
|
-
end
|
15
|
+
part :unit_procedure
|
15
16
|
|
16
|
-
|
17
|
-
return settings[key] if settings.has_key? key
|
17
|
+
# SETTINGS
|
18
18
|
|
19
|
-
|
19
|
+
def self.settings
|
20
|
+
@settings ||= {}
|
21
|
+
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
def self.get key
|
24
|
+
return settings[key] if settings.has_key? key
|
23
25
|
|
24
|
-
|
25
|
-
found = klass.settings[key]
|
26
|
+
found = nil
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
28
|
+
for klass in ancestors
|
29
|
+
break unless klass.respond_to? :settings
|
30
30
|
|
31
|
-
|
31
|
+
if klass.settings.has_key? key
|
32
|
+
found = klass.settings[key]
|
32
33
|
|
33
|
-
|
34
|
+
break
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
|
-
|
37
|
-
settings[key] = value
|
38
|
-
value
|
39
|
-
end
|
38
|
+
found = settings[key] = found.dup if found.is_a? Enumerable
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
fetch(list) { Hash.new }[key] = value
|
44
|
-
else
|
45
|
-
fetch(list) { Set.new } << value
|
46
|
-
end
|
47
|
-
end
|
40
|
+
found
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
43
|
+
def self.set key, value
|
44
|
+
settings[key] = value
|
45
|
+
value
|
46
|
+
end
|
54
47
|
|
55
|
-
|
56
|
-
|
48
|
+
def self.add list, key = nil, value
|
49
|
+
if key
|
50
|
+
fetch(list) { Hash.new }[key] = value
|
51
|
+
else
|
52
|
+
fetch(list) { Set.new } << value
|
57
53
|
end
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
56
|
+
def self.fetch key, &block
|
57
|
+
x = get key
|
58
|
+
x ||= set key, instance_eval(&block)
|
59
|
+
x
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
def settings
|
63
|
+
@settings ||= {}
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
end
|
66
|
+
def get key
|
67
|
+
return settings[key] if settings.has_key? key
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
69
|
+
self.class.get key
|
70
|
+
end
|
71
|
+
|
72
|
+
def set key, value
|
73
|
+
settings[key] = value
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
def add list, key = nil, value
|
77
|
+
if key
|
78
|
+
fetch(list) { Hash.new }[key] = value
|
79
|
+
else
|
80
|
+
fetch(list) { Set.new } << value
|
81
81
|
end
|
82
|
+
end
|
82
83
|
|
83
|
-
|
84
|
+
def fetch key, &block
|
85
|
+
x = get key
|
86
|
+
x ||= set key, eval(&block)
|
87
|
+
x
|
88
|
+
end
|
84
89
|
|
85
|
-
|
86
|
-
:higher => 2,
|
87
|
-
:high => 1,
|
88
|
-
:normal => 0,
|
89
|
-
:low => -1,
|
90
|
-
:lower => -2,
|
91
|
-
}
|
90
|
+
# LOG
|
92
91
|
|
93
|
-
|
94
|
-
|
92
|
+
LOG_LEVELS = {
|
93
|
+
:higher => 2,
|
94
|
+
:high => 1,
|
95
|
+
:normal => 0,
|
96
|
+
:low => -1,
|
97
|
+
:lower => -2,
|
98
|
+
}
|
95
99
|
|
96
|
-
|
100
|
+
set :log_level, :normal
|
101
|
+
set :log_color, :white
|
97
102
|
|
98
|
-
|
103
|
+
#
|
99
104
|
|
100
|
-
|
101
|
-
raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
|
102
|
-
return unless log_level? log_level
|
105
|
+
LOG_JUST = 40
|
103
106
|
|
104
|
-
|
105
|
-
|
107
|
+
def self.log log_level = :normal, string
|
108
|
+
raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
|
109
|
+
return unless log_level? log_level
|
106
110
|
|
107
|
-
|
111
|
+
source = (self.is_a? Class) ? self : self.class
|
112
|
+
source = source.to_s.ljust(LOG_JUST).bold.colorize(source.log_color)
|
108
113
|
|
109
|
-
|
110
|
-
end
|
114
|
+
string = "#{source} #{string}"
|
111
115
|
|
112
|
-
|
113
|
-
|
114
|
-
end
|
116
|
+
DevBox[:log].call string
|
117
|
+
end
|
115
118
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
119
|
+
def self.log_level
|
120
|
+
get(:log_level) || :normal
|
121
|
+
end
|
120
122
|
|
121
|
-
|
122
|
-
|
123
|
-
|
123
|
+
def self.log_level? log_level = :normal
|
124
|
+
# TODO
|
125
|
+
true
|
126
|
+
end
|
124
127
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
def log?(...)= self.class.log?(...)
|
129
|
-
def log_level?(...)= self.class.log_level?(...)
|
130
|
-
def log_color(...)= self.class.log_color(...)
|
128
|
+
def self.log_color
|
129
|
+
(get(:system) || self).get :log_color
|
130
|
+
end
|
131
131
|
|
132
|
-
|
132
|
+
def self.log?(log_level = :normal)= log_level? log_level
|
133
|
+
def log(...)= self.class.log(...)
|
134
|
+
def log_level(...)= self.class.log_level(...)
|
135
|
+
def log?(...)= self.class.log?(...)
|
136
|
+
def log_level?(...)= self.class.log_level?(...)
|
137
|
+
def log_color(...)= self.class.log_color(...)
|
133
138
|
|
134
|
-
|
139
|
+
# SYSTEM
|
135
140
|
|
136
|
-
|
137
|
-
super
|
141
|
+
def self.inherited_explicitly_sets_system
|
138
142
|
|
139
|
-
|
143
|
+
def self.inherited sub
|
144
|
+
super
|
140
145
|
|
141
|
-
|
146
|
+
return unless sub.name.to_s.include? "::"
|
142
147
|
|
143
|
-
|
144
|
-
end
|
148
|
+
system = Object.const_get sub.first_namespace
|
145
149
|
|
150
|
+
sub.set :system, system
|
146
151
|
end
|
147
152
|
|
148
153
|
end
|
154
|
+
|
149
155
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Liza::UnitProcedurePart < Liza::Part
|
2
|
+
|
3
|
+
insertion do
|
4
|
+
def self.procedure _label, &block
|
5
|
+
catch :procedure, &block
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.proceed val = nil, &block
|
9
|
+
val = yield if val.nil? && block_given?
|
10
|
+
throw :procedure, val
|
11
|
+
end
|
12
|
+
|
13
|
+
def procedure(_label, &block)= self.class.procedure _label, &block
|
14
|
+
def proceed(...)= self.class.proceed(...)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Liza::UnitProcedurePartTest < Liza::UnitTest
|
2
|
+
|
3
|
+
test :procedure_scopes_and_returns do
|
4
|
+
b = nil
|
5
|
+
|
6
|
+
w =
|
7
|
+
procedure "creates a new scope" do
|
8
|
+
@a = 1
|
9
|
+
b = 2
|
10
|
+
c = 3
|
11
|
+
assert true
|
12
|
+
|
13
|
+
proceed if true
|
14
|
+
raise "did not get here"
|
15
|
+
end
|
16
|
+
|
17
|
+
assert assertions > 0
|
18
|
+
assert w.nil?
|
19
|
+
|
20
|
+
x =
|
21
|
+
procedure "asserts old scope is not accessible" do
|
22
|
+
assert instance_variables.include? :@a
|
23
|
+
assert local_variables.include? :b
|
24
|
+
refute local_variables.include? :c
|
25
|
+
|
26
|
+
assert @a == 1
|
27
|
+
assert b == 2
|
28
|
+
|
29
|
+
proceed 100 if true
|
30
|
+
raise "did not get here"
|
31
|
+
end
|
32
|
+
|
33
|
+
assert x == 100
|
34
|
+
|
35
|
+
y =
|
36
|
+
procedure "asserts proceed calls can be lazy" do
|
37
|
+
proceed { "slow operation"; 200 } if true
|
38
|
+
raise "did not get here"
|
39
|
+
end
|
40
|
+
|
41
|
+
assert y == 200
|
42
|
+
end
|
43
|
+
|
44
|
+
test :procedure_rescue_and_ensure do
|
45
|
+
procedure "assert ensure works" do
|
46
|
+
@a = 1
|
47
|
+
ensure
|
48
|
+
@a = 2
|
49
|
+
end
|
50
|
+
|
51
|
+
assert @a == 2
|
52
|
+
|
53
|
+
procedure "assert rescue works" do
|
54
|
+
@a = [1]
|
55
|
+
raise "a runtime error!"
|
56
|
+
rescue RuntimeError
|
57
|
+
@a << 2
|
58
|
+
ensure
|
59
|
+
@a << 3
|
60
|
+
end
|
61
|
+
|
62
|
+
assert @a == [1, 2, 3]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/liza/unit_test.rb
CHANGED
@@ -1,79 +1,77 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Liza::UnitTest < Liza::Test
|
2
|
+
test :subject_class do
|
3
|
+
assert subject_class == Liza::Unit
|
4
|
+
end
|
5
|
+
|
6
|
+
test :settings do
|
7
|
+
assert subject_class.get(:log_level) == :normal
|
8
|
+
assert subject_class.get(:log_color) == :white
|
9
|
+
assert subject_class.log_level == :normal
|
10
|
+
assert subject_class.log_color == :white
|
11
|
+
|
12
|
+
assert subject_class.settings == {log_level: :normal, log_color: :white}
|
13
|
+
end
|
14
|
+
|
15
|
+
test :settings_inheritance do
|
16
|
+
class_a = Class.new(subject_class) do
|
17
|
+
set :number, 1
|
18
|
+
|
19
|
+
add :default, 10
|
20
|
+
add :default, 20
|
6
21
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
assert subject_class.log_level == :normal
|
11
|
-
assert subject_class.log_color == :white
|
22
|
+
set :array, []
|
23
|
+
add :array, 10
|
24
|
+
add :array, 20
|
12
25
|
|
13
|
-
|
26
|
+
add :hash, :a, 10
|
27
|
+
add :hash, :b, 20
|
14
28
|
end
|
15
29
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert class_a.get(:default) == Set[10, 20]
|
39
|
-
assert class_a.get(:array) == [10, 20]
|
40
|
-
assert class_a.get(:hash) == {a: 10, b: 20}
|
41
|
-
|
42
|
-
class_b = Class.new(class_a) do
|
43
|
-
set :string, "a"
|
44
|
-
|
45
|
-
add :default, 30
|
46
|
-
add :default, 40
|
47
|
-
|
48
|
-
add :array, 30
|
49
|
-
add :array, 40
|
50
|
-
|
51
|
-
add :hash, :c, 30
|
52
|
-
add :hash, :d, 40
|
53
|
-
end
|
54
|
-
|
55
|
-
assert class_a.settings == {
|
56
|
-
number: 1,
|
57
|
-
default: Set[10, 20],
|
58
|
-
array: [10, 20],
|
59
|
-
hash: {a: 10, b: 20}
|
60
|
-
}
|
61
|
-
|
62
|
-
assert class_a.get(:default) == Set[10, 20]
|
63
|
-
assert class_a.get(:array) == [10, 20]
|
64
|
-
assert class_a.get(:hash) == {a: 10, b: 20}
|
65
|
-
|
66
|
-
assert class_b.settings == {
|
67
|
-
string: "a",
|
68
|
-
default: Set[10, 20, 30, 40],
|
69
|
-
array: [10, 20, 30, 40],
|
70
|
-
hash: {a: 10, b: 20, c: 30, d: 40}
|
71
|
-
}
|
72
|
-
|
73
|
-
assert class_b.get(:default) == Set[10, 20, 30, 40]
|
74
|
-
assert class_b.get(:array) == [10, 20, 30, 40]
|
75
|
-
assert class_b.get(:hash) == {a: 10, b: 20, c: 30, d: 40}
|
30
|
+
assert class_a.settings == {
|
31
|
+
number: 1,
|
32
|
+
default: Set[10, 20],
|
33
|
+
array: [10, 20],
|
34
|
+
hash: {a: 10, b: 20}
|
35
|
+
}
|
36
|
+
|
37
|
+
assert class_a.get(:default) == Set[10, 20]
|
38
|
+
assert class_a.get(:array) == [10, 20]
|
39
|
+
assert class_a.get(:hash) == {a: 10, b: 20}
|
40
|
+
|
41
|
+
class_b = Class.new(class_a) do
|
42
|
+
set :string, "a"
|
43
|
+
|
44
|
+
add :default, 30
|
45
|
+
add :default, 40
|
46
|
+
|
47
|
+
add :array, 30
|
48
|
+
add :array, 40
|
49
|
+
|
50
|
+
add :hash, :c, 30
|
51
|
+
add :hash, :d, 40
|
76
52
|
end
|
77
53
|
|
54
|
+
assert class_a.settings == {
|
55
|
+
number: 1,
|
56
|
+
default: Set[10, 20],
|
57
|
+
array: [10, 20],
|
58
|
+
hash: {a: 10, b: 20}
|
59
|
+
}
|
60
|
+
|
61
|
+
assert class_a.get(:default) == Set[10, 20]
|
62
|
+
assert class_a.get(:array) == [10, 20]
|
63
|
+
assert class_a.get(:hash) == {a: 10, b: 20}
|
64
|
+
|
65
|
+
assert class_b.settings == {
|
66
|
+
string: "a",
|
67
|
+
default: Set[10, 20, 30, 40],
|
68
|
+
array: [10, 20, 30, 40],
|
69
|
+
hash: {a: 10, b: 20, c: 30, d: 40}
|
70
|
+
}
|
71
|
+
|
72
|
+
assert class_b.get(:default) == Set[10, 20, 30, 40]
|
73
|
+
assert class_b.get(:array) == [10, 20, 30, 40]
|
74
|
+
assert class_b.get(:hash) == {a: 10, b: 20, c: 30, d: 40}
|
78
75
|
end
|
76
|
+
|
79
77
|
end
|
data/lib/liza.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Liza
|
4
4
|
class Error < StandardError; end
|
5
|
+
class ConstNotFound < Error; end
|
5
6
|
|
6
7
|
#
|
7
8
|
|
@@ -27,6 +28,8 @@ module Liza
|
|
27
28
|
return k if k
|
28
29
|
|
29
30
|
nil
|
31
|
+
rescue NameError
|
32
|
+
raise ConstNotFound, name
|
30
33
|
end
|
31
34
|
|
32
35
|
# Checks each system, then Liza for Liza::Unit classes
|
@@ -46,6 +49,8 @@ module Liza
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def const_check_systems name
|
52
|
+
App.systems.frozen? or return nil
|
53
|
+
|
49
54
|
for k in App.systems.values.reverse
|
50
55
|
next if not k.const_defined? name.to_sym
|
51
56
|
kk = k.const(name) if k.constants.include? name
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Module
|
4
|
+
|
5
|
+
# /path/to/liza.rb
|
6
|
+
def source_location
|
7
|
+
Object.const_source_location name
|
8
|
+
end
|
9
|
+
|
10
|
+
# /path/to/liza
|
11
|
+
def source_location_radical
|
12
|
+
source_location[0][0..-4]
|
13
|
+
rescue
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/lizarb/ruby/string.rb
CHANGED
@@ -3,10 +3,18 @@
|
|
3
3
|
class String
|
4
4
|
alias lpartition partition
|
5
5
|
|
6
|
-
def
|
7
|
-
split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
|
6
|
+
def camelcase
|
7
|
+
split("_").map { |s| "#{s[0].to_s.upcase}#{s[1..-1]}" }.join("")
|
8
8
|
end
|
9
9
|
|
10
|
+
alias camelize camelcase
|
11
|
+
|
12
|
+
def snakecase
|
13
|
+
gsub(/[A-Z\s-]/) { |s, t| "_#{s}" }[1..-1].to_s.downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
alias snakefy snakecase
|
17
|
+
|
10
18
|
def rjust_blanks length
|
11
19
|
rjust length, " "
|
12
20
|
end
|
data/lib/lizarb/version.rb
CHANGED
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
|
-
|
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,14 +1,13 @@
|
|
1
|
-
class NetSystem
|
2
|
-
class NetCommand < Liza::Command
|
1
|
+
class NetSystem::NetCommand < Liza::Command
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
def self.call args
|
4
|
+
log :higher, "Called #{self} with args #{args}"
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
ruby_time = Time.now
|
7
|
+
redis_time = ::NetBox.databases.redis.now
|
8
|
+
sqlite_time = ::NetBox.databases.sqlite.now
|
9
|
+
# redis_time = ::RedisDb.current.now
|
10
|
+
# sqlite_time = ::SqliteDb.current.now
|
12
11
|
|
13
12
|
puts <<-OUTPUT.bold
|
14
13
|
|
@@ -17,8 +16,7 @@ class NetSystem
|
|
17
16
|
Time for Sqlite: #{sqlite_time.to_s.light_red}
|
18
17
|
|
19
18
|
OUTPUT
|
20
|
-
|
21
|
-
end
|
22
|
-
|
19
|
+
Liza::DevCommand.call []
|
23
20
|
end
|
21
|
+
|
24
22
|
end
|