lizarb 1.0.0 → 1.0.2
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 +2 -0
- data/Gemfile.lock +14 -3
- data/README.md +23 -64
- data/README_SYSTEMS.md +80 -0
- data/Rakefile +3 -1
- data/app/dev/benches/app_bench.rb +5 -0
- data/app/dev/benches/app_bench_test.rb +7 -0
- data/app/dev/benches/loops_bench.rb +183 -0
- data/app/dev/benches/loops_bench_test.rb +11 -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/new_command.rb +1 -61
- 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 +18 -0
- data/app/dev/generators/bench_generator_test.rb +12 -0
- 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 +18 -0
- data/app/dev/generators/command_generator_test.rb +12 -0
- data/app/dev/generators/record_generator.rb +46 -0
- data/app/dev/generators/record_generator_test.rb +12 -0
- data/app/dev/generators/request_generator.rb +63 -0
- data/app/dev/generators/request_generator_test.rb +12 -0
- data/app/net/databases/redis_db_test.rb +2 -2
- data/app/net/databases/sqlite_db_test.rb +2 -2
- data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
- data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
- data/app/net/records/post_record.rb +4 -0
- data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
- data/app/net/records/user_record.rb +4 -0
- data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
- data/app/net_box.rb +2 -2
- 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 +8 -0
- data/app_new/Procfile +1 -1
- data/exe/lrb +3 -0
- data/lib/app.rb +18 -14
- data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
- data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
- data/lib/dev_system/dev/controllers/bench.rb +11 -0
- data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
- data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench_test.rb} +2 -2
- data/lib/dev_system/dev/controllers/command/bench_command.rb +34 -0
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/generate_command.rb +35 -0
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
- data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/terminal_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
- data/lib/dev_system/dev/controllers/generator.rb +11 -0
- data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
- data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +96 -0
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
- 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 +29 -0
- data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -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 +59 -0
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +150 -0
- 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 +31 -0
- data/lib/dev_system/dev/controllers/shell_test.rb +46 -0
- data/lib/dev_system/dev/controllers/{command/dev_command.rb → terminal/irb_terminal.rb} +2 -2
- data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
- data/lib/dev_system/dev/dev_box.rb +3 -0
- data/lib/dev_system/dev/panels/command_panel.rb +21 -1
- data/lib/dev_system/dev/panels/log_panel.rb +1 -1
- data/lib/lerb.rb +106 -0
- data/lib/liza/base/controller.rb +2 -0
- data/lib/liza/base/panel.rb +6 -5
- 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_extension.rb +6 -1
- data/lib/liza/ruby_test.rb +9 -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 +3 -1
- data/lib/liza/test/test_test.rb +108 -15
- data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
- data/lib/liza/test_parts/test_assertions_part.rb +7 -6
- data/lib/liza/test_parts/test_dsl_part.rb +37 -89
- data/lib/liza/test_parts/test_log_part.rb +124 -0
- data/lib/liza/test_parts/test_subject_part.rb +6 -1
- data/lib/liza/test_parts/test_tree_part.rb +139 -0
- data/lib/liza/unit.rb +2 -0
- 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.rb +40 -7
- data/lib/lizarb/ruby/class.rb +2 -0
- data/lib/lizarb/ruby/module.rb +17 -0
- data/lib/lizarb/ruby/proc.rb +12 -0
- data/lib/lizarb/ruby/string.rb +26 -2
- data/lib/lizarb/version.rb +1 -1
- data/lib/lizarb.rb +24 -2
- data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
- data/lib/net_system/net/controllers/client.rb +5 -0
- data/lib/net_system/net/controllers/{model_test.rb → client_test.rb} +2 -2
- data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
- data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
- data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
- data/lib/net_system/net/controllers/database.rb +6 -6
- data/lib/net_system/net/controllers/record.rb +31 -0
- data/lib/net_system/net/controllers/{adapter_test.rb → record_test.rb} +2 -2
- data/lib/net_system/net/net_box.rb +5 -5
- data/lib/net_system/net/net_box_test.rb +1 -1
- data/lib/net_system/net/panels/client_panel.rb +5 -0
- data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
- data/lib/web_system/dev/rack_command.rb +26 -0
- data/lib/web_system/dev/request_command.rb +143 -0
- data/lib/web_system/dev/web_command.rb +3 -34
- data/lib/web_system/web/controllers/rack.rb +8 -0
- data/lib/web_system/web/controllers/rack_test.rb +18 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
- data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
- data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
- data/lib/web_system/web/panels/rack_panel.rb +44 -0
- data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
- data/lib/web_system/web/panels/request_panel.rb +51 -32
- data/lib/web_system/web/panels/request_panel_test.rb +28 -9
- data/lib/web_system/web/web_box.rb +12 -0
- data/lizarb.gemspec +2 -2
- data/tmp/.gitkeep +0 -0
- metadata +110 -31
- 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/net/models/post_model.rb +0 -4
- data/app/net/models/user_model.rb +0 -4
- data/lib/liza/test_parts/test_context_part.rb +0 -81
- data/lib/net_system/net/controllers/adapter.rb +0 -5
- data/lib/net_system/net/controllers/model.rb +0 -31
- data/lib/net_system/net/panels/adapter_panel.rb +0 -5
@@ -0,0 +1,76 @@
|
|
1
|
+
class CircleCommandTest < NarrativeMethodCommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == CircleCommand
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :green
|
10
|
+
end
|
11
|
+
|
12
|
+
test :subject_class, :area do
|
13
|
+
assert subject_class.area(1) == 3.141592653589793
|
14
|
+
end
|
15
|
+
|
16
|
+
test :subject_class, :circumference do
|
17
|
+
assert subject_class.circumference(1) == 6.283185307179586
|
18
|
+
end
|
19
|
+
|
20
|
+
test :validate, :valid, :area do
|
21
|
+
subject = subject_class.new
|
22
|
+
subject.instance_variable_set :@args, ["area", "1"]
|
23
|
+
subject.validate
|
24
|
+
assert subject.instance_variable_get(:@radius) == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
test :validate, :invalid, :area do
|
28
|
+
subject = subject_class.new
|
29
|
+
subject.instance_variable_set :@args, ["area", "0"]
|
30
|
+
begin
|
31
|
+
subject.validate
|
32
|
+
assert false
|
33
|
+
rescue CircleCommand::Invalid
|
34
|
+
assert true
|
35
|
+
else
|
36
|
+
assert false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test :validate, :valid, :circumference do
|
41
|
+
subject = subject_class.new
|
42
|
+
subject.instance_variable_set :@args, ["circumference", "1"]
|
43
|
+
subject.validate
|
44
|
+
assert subject.instance_variable_get(:@radius) == 1
|
45
|
+
end
|
46
|
+
|
47
|
+
test :validate, :invalid, :circumference do
|
48
|
+
subject = subject_class.new
|
49
|
+
subject.instance_variable_set :@args, ["circumference", "0"]
|
50
|
+
begin
|
51
|
+
subject.validate
|
52
|
+
assert false
|
53
|
+
rescue CircleCommand::Invalid
|
54
|
+
assert true
|
55
|
+
else
|
56
|
+
assert false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test :perform, :area do
|
61
|
+
subject = subject_class.new
|
62
|
+
subject.instance_variable_set :@args, ["area", "1"]
|
63
|
+
subject.validate
|
64
|
+
subject.perform
|
65
|
+
assert subject.instance_variable_get(:@result) == 3.141592653589793
|
66
|
+
end
|
67
|
+
|
68
|
+
test :perform, :circumference do
|
69
|
+
subject = subject_class.new
|
70
|
+
subject.instance_variable_set :@args, ["circumference", "1"]
|
71
|
+
subject.validate
|
72
|
+
subject.perform
|
73
|
+
assert subject.instance_variable_get(:@result) == 6.283185307179586
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class NarrativeMethodCommand < Liza::Command
|
2
|
+
class Error < StandardError; end
|
3
|
+
class Invalid < Error; end
|
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
|
+
return help if args.empty?
|
15
|
+
|
16
|
+
@args = args
|
17
|
+
validate
|
18
|
+
perform
|
19
|
+
rescue StandardError => error
|
20
|
+
@error = error
|
21
|
+
handle
|
22
|
+
ensure
|
23
|
+
@result
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate
|
27
|
+
raise NotImplementedError
|
28
|
+
end
|
29
|
+
|
30
|
+
def perform
|
31
|
+
raise NotImplementedError
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle
|
35
|
+
log "Called #{self}.#{__method__}"
|
36
|
+
log render "error.txt"
|
37
|
+
end
|
38
|
+
|
39
|
+
def help
|
40
|
+
log "Called #{self}.#{__method__}"
|
41
|
+
log render "help.txt"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
__END__
|
46
|
+
|
47
|
+
# success.txt.erb
|
48
|
+
|
49
|
+
RESULT:
|
50
|
+
|
51
|
+
class <%= @result.class %>
|
52
|
+
value <%= @result %>
|
53
|
+
|
54
|
+
# error.txt.erb
|
55
|
+
|
56
|
+
ERROR:
|
57
|
+
|
58
|
+
class <%= @error.class %>
|
59
|
+
message <%= @error.message %>
|
60
|
+
backtrace <%= @error.backtrace.select { |s| @stop = true if s.include?("/exe/lizarb:"); !defined? @stop }.join "\n " %>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class NarrativeMethodCommandTest < Liza::CommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == NarrativeMethodCommand
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :green
|
10
|
+
end
|
11
|
+
|
12
|
+
test :validate, :not_implemented do
|
13
|
+
subject = subject_class.new
|
14
|
+
begin
|
15
|
+
subject.validate
|
16
|
+
assert false
|
17
|
+
rescue NotImplementedError
|
18
|
+
assert true
|
19
|
+
else
|
20
|
+
assert false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test :perform, :not_implemented do
|
25
|
+
subject = subject_class.new
|
26
|
+
begin
|
27
|
+
subject.perform
|
28
|
+
assert false
|
29
|
+
rescue NotImplementedError
|
30
|
+
assert true
|
31
|
+
else
|
32
|
+
assert false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -3,67 +3,7 @@ class NewCommand < AppCommand
|
|
3
3
|
def self.call args
|
4
4
|
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
name = args.shift || "app_1"
|
9
|
-
|
10
|
-
from = "#{Lizarb::APP_DIR}/app_new"
|
11
|
-
to = name
|
12
|
-
|
13
|
-
return log "Directory #{to.light_green} already exists." if Dir.exist? to
|
14
|
-
|
15
|
-
log "Liza Application initializing at `#{to}`"
|
16
|
-
|
17
|
-
# init
|
18
|
-
|
19
|
-
require "fileutils"
|
20
|
-
FileUtils.cp_r from, to, verbose: true
|
21
|
-
|
22
|
-
`cd #{to}; git init .`
|
23
|
-
|
24
|
-
# extra
|
25
|
-
|
26
|
-
puts
|
27
|
-
FileUtils.mkdir_p "#{to}/app", verbose: true
|
28
|
-
|
29
|
-
FileUtils.mkdir_p "#{to}/lib", verbose: true
|
30
|
-
FileUtils.touch "#{to}/lib/.gitkeep", verbose: true
|
31
|
-
FileUtils.mkdir_p "#{to}/tmp", verbose: true
|
32
|
-
FileUtils.touch "#{to}/tmp/.gitkeep", verbose: true
|
33
|
-
|
34
|
-
# systems
|
35
|
-
|
36
|
-
App.systems.keys.each { |system_name| copy name, system_name }
|
37
|
-
|
38
|
-
FileUtils.rm "#{to}/app/dev/commands/new_command.rb"
|
39
|
-
FileUtils.rm "#{to}/app/dev/commands/new_command_test.rb"
|
40
|
-
|
41
|
-
FileUtils.cp_r "#{Lizarb::APP_DIR}/.ruby-version", "#{to}/.ruby-version", verbose: true
|
42
|
-
FileUtils.cp_r "#{Lizarb::APP_DIR}/README.md", "#{to}/README.md", verbose: true
|
43
|
-
FileUtils.cp_r "#{Lizarb::APP_DIR}/app.rb", "#{to}/app.rb", verbose: true
|
44
|
-
FileUtils.cp_r "#{Lizarb::APP_DIR}/app.env", "#{to}/app.env", verbose: true
|
45
|
-
FileUtils.cp_r "#{Lizarb::APP_DIR}/app.code.env", "#{to}/app.code.env", verbose: true
|
46
|
-
puts
|
47
|
-
|
48
|
-
log "Liza Application initialized at `#{to}`"
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.copy name, system_name
|
52
|
-
from = "#{Lizarb::APP_DIR}/app/#{system_name}_box.rb"
|
53
|
-
to = "#{name}/app"
|
54
|
-
if File.exist? from
|
55
|
-
FileUtils.cp_r from, to, verbose: true
|
56
|
-
else
|
57
|
-
puts "file not found #{from}"
|
58
|
-
end
|
59
|
-
|
60
|
-
from = "#{Lizarb::APP_DIR}/app/#{system_name}"
|
61
|
-
to = "#{name}/app"
|
62
|
-
if File.exist? from
|
63
|
-
FileUtils.cp_r from, to, verbose: true
|
64
|
-
else
|
65
|
-
puts "file not found #{from}"
|
66
|
-
end
|
6
|
+
Liza::GenerateCommand.call ["app", *args]
|
67
7
|
end
|
68
8
|
|
69
9
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class QuadraticCommand < NarrativeMethodCommand
|
2
|
+
class Error < Error; end
|
3
|
+
|
4
|
+
def self.quadratic(a, b, c)
|
5
|
+
d = b**2 - 4 * a * c
|
6
|
+
case
|
7
|
+
when d < 0
|
8
|
+
[]
|
9
|
+
when d == 0
|
10
|
+
[-b / (2 * a)]
|
11
|
+
else
|
12
|
+
[(-b + Math.sqrt(d)) / (2 * a), (-b - Math.sqrt(d)) / (2 * a)].sort
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# instance methods
|
17
|
+
|
18
|
+
def validate
|
19
|
+
log "Called #{self}.#{__method__}"
|
20
|
+
raise Invalid, "liza quadratic 0 0 0" if @args.size != 3
|
21
|
+
|
22
|
+
@a = @args[0].to_f
|
23
|
+
@b = @args[1].to_f
|
24
|
+
@c = @args[2].to_f
|
25
|
+
|
26
|
+
log "@a = #{@a}"
|
27
|
+
log "@b = #{@b}"
|
28
|
+
log "@c = #{@c}"
|
29
|
+
|
30
|
+
raise Invalid, "a can't be zero" if @a == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def perform
|
34
|
+
log "Called #{self}.#{__method__}"
|
35
|
+
|
36
|
+
@result = self.class.quadratic(@a, @b, @c)
|
37
|
+
log "RESULT: #{@result}"
|
38
|
+
log render "success.txt"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
__END__
|
44
|
+
|
45
|
+
# help.txt.erb
|
46
|
+
|
47
|
+
NAME:
|
48
|
+
|
49
|
+
liza quadratic
|
50
|
+
|
51
|
+
DESCRIPTION:
|
52
|
+
|
53
|
+
Calculates the result of a quadratic equation.
|
54
|
+
|
55
|
+
USAGE:
|
56
|
+
|
57
|
+
liza quadratic <a> <b> <c>
|
58
|
+
|
59
|
+
where <a>, <b> and <c> are numbers.
|
60
|
+
|
61
|
+
EXAMPLES:
|
62
|
+
|
63
|
+
liza quadratic 1 0 0
|
64
|
+
liza quadratic 1 0 1
|
65
|
+
liza quadratic 1 1 1
|
66
|
+
liza quadratic 1 2 1
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class QuadraticCommandTest < NarrativeMethodCommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == QuadraticCommand
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :green
|
10
|
+
end
|
11
|
+
|
12
|
+
test :subject_class, :quadratic do
|
13
|
+
assert subject_class.quadratic(1, -11, 30) == [5, 6]
|
14
|
+
assert subject_class.quadratic(1, +11, 30) == [-6, -5]
|
15
|
+
end
|
16
|
+
|
17
|
+
test :validate, :valid do
|
18
|
+
subject = subject_class.new
|
19
|
+
subject.instance_variable_set :@args, ["1", "2", "3"]
|
20
|
+
subject.validate
|
21
|
+
assert subject.instance_variable_get(:@a) == 1
|
22
|
+
assert subject.instance_variable_get(:@b) == 2
|
23
|
+
assert subject.instance_variable_get(:@c) == 3
|
24
|
+
end
|
25
|
+
|
26
|
+
test :validate, :invalid do
|
27
|
+
subject = subject_class.new
|
28
|
+
subject.instance_variable_set :@args, ["0", "2", "3"]
|
29
|
+
begin
|
30
|
+
subject.validate
|
31
|
+
assert false
|
32
|
+
rescue QuadraticCommand::Invalid
|
33
|
+
assert true
|
34
|
+
else
|
35
|
+
assert false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
test :perform do
|
40
|
+
subject = subject_class.new
|
41
|
+
subject.instance_variable_set :@args, ["1", "-11", "30"]
|
42
|
+
subject.validate
|
43
|
+
subject.perform
|
44
|
+
assert subject.instance_variable_get(:@result) == [5, 6]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class <%= name.camelize %>Bench < AppBench
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
setup do
|
5
|
+
N = 1_000_000
|
6
|
+
end
|
7
|
+
|
8
|
+
mark "alternative 1" do
|
9
|
+
i = 0
|
10
|
+
|
11
|
+
while (i += 1) <= N
|
12
|
+
a = "1".to_sym
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
mark "alternative 2" do
|
17
|
+
i = 0
|
18
|
+
|
19
|
+
while (i += 1) <= N
|
20
|
+
a = :"1"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= name.camelize %>BenchTest < AppBenchTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == <%= name.camelize %>Bench
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :green
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class BenchGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/benches"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_bench.rb"
|
9
|
+
content render "bench.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_bench_test.rb"
|
15
|
+
content render "bench_test.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class <%= name.camelize %>Command < AppCommand
|
2
|
+
|
3
|
+
def self.call args
|
4
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
5
|
+
new(args).call
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize args
|
9
|
+
@args = args
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
log :higher, "Called #{self}.#{__method__}"
|
14
|
+
|
15
|
+
text = render "text.txt"
|
16
|
+
|
17
|
+
log :higher, "text: #{text}"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
__END__
|
23
|
+
|
24
|
+
# text.txt.erb
|
25
|
+
Called <%%= self %>.<%%= __method__ %>
|
26
|
+
@args: <%%= @args %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= name.camelize %>CommandTest < AppCommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == <%= name.camelize %>Command
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.log_level == :normal
|
9
|
+
assert subject_class.log_color == :green
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CommandGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/commands"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_command.rb"
|
9
|
+
content render "command.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_command_test.rb"
|
15
|
+
content render "command_test.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class RecordGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/net/records"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_record.rb"
|
9
|
+
content record_content name
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_record_test.rb"
|
15
|
+
content record_test_content name
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def record_content name
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Record < AppRecord
|
23
|
+
set :table, :#{name}s
|
24
|
+
|
25
|
+
end
|
26
|
+
CODE
|
27
|
+
end
|
28
|
+
|
29
|
+
def record_test_content name
|
30
|
+
<<~CODE
|
31
|
+
class #{name.camelize}RecordTest < Liza::RecordTest
|
32
|
+
|
33
|
+
test :subject_class do
|
34
|
+
assert subject_class == #{name.camelize}Record
|
35
|
+
end
|
36
|
+
|
37
|
+
test :settings do
|
38
|
+
assert subject_class.log_level == :normal
|
39
|
+
assert subject_class.log_color == :red
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
CODE
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class RequestGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/web/requests"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder "app/web/requests"
|
8
|
+
filename "#{name}_request.rb"
|
9
|
+
content request_content name
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder "app/web/requests"
|
14
|
+
filename "#{name}_request_test.rb"
|
15
|
+
content request_test_content name
|
16
|
+
end
|
17
|
+
|
18
|
+
# helper methods
|
19
|
+
|
20
|
+
def request_content name
|
21
|
+
<<~CODE
|
22
|
+
class #{name.camelize}Request < Liza::Request
|
23
|
+
|
24
|
+
def self.call env
|
25
|
+
path = env["REQUEST_PATH"]
|
26
|
+
log :higher, "Called \#{self}.\#{__method__} with path \#{path}"
|
27
|
+
|
28
|
+
#
|
29
|
+
|
30
|
+
status = 200
|
31
|
+
headers = {
|
32
|
+
"Framework" => "Liza \#{Lizarb::VERSION}"
|
33
|
+
}
|
34
|
+
body = "It works!"
|
35
|
+
|
36
|
+
#
|
37
|
+
|
38
|
+
log status
|
39
|
+
[status, headers, [body]]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
CODE
|
44
|
+
end
|
45
|
+
|
46
|
+
def request_test_content name
|
47
|
+
<<~CODE
|
48
|
+
class #{name.camelize}RequestTest < Liza::RequestTest
|
49
|
+
|
50
|
+
test :subject_class do
|
51
|
+
assert subject_class == #{name.camelize}Request
|
52
|
+
end
|
53
|
+
|
54
|
+
test :settings do
|
55
|
+
assert subject_class.log_level == :normal
|
56
|
+
assert subject_class.log_color == :blue
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
CODE
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -5,8 +5,8 @@ class RedisDbTest < Liza::RedisDbTest
|
|
5
5
|
assert RedisDb.current.class == RedisDb
|
6
6
|
assert Liza::RedisDb.current.class == RedisDb
|
7
7
|
assert RedisDb.current == Liza::RedisDb.current
|
8
|
-
assert RedisDb.current.
|
9
|
-
assert RedisDb.current.
|
8
|
+
assert RedisDb.current.client == Liza::RedisDb.current.client
|
9
|
+
assert RedisDb.current.client.conn == Liza::RedisDb.current.client.conn
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -5,8 +5,8 @@ class SqliteDbTest < Liza::SqliteDbTest
|
|
5
5
|
assert SqliteDb.current.class == SqliteDb
|
6
6
|
assert Liza::SqliteDb.current.class == SqliteDb
|
7
7
|
assert SqliteDb.current == Liza::SqliteDb.current
|
8
|
-
assert SqliteDb.current.
|
9
|
-
assert SqliteDb.current.
|
8
|
+
assert SqliteDb.current.client == Liza::SqliteDb.current.client
|
9
|
+
assert SqliteDb.current.client.conn == Liza::SqliteDb.current.client.conn
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|