lizarb 1.0.1 → 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 +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/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/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/command/bench_command.rb +11 -1
- data/lib/dev_system/dev/controllers/command/generate_command.rb +14 -2
- data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
- data/lib/dev_system/dev/controllers/command/{dev_command_test.rb → not_found_command_test.rb} +2 -2
- data/lib/dev_system/dev/controllers/command/{dev_command.rb → terminal_command.rb} +1 -1
- 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_dsl_main_part.rb +1 -1
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +30 -5
- 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 +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/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_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 +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/net/controllers/record.rb +31 -0
- data/lib/net_system/net/controllers/{model_test.rb → record_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
- metadata +68 -25
- 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/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/model.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebe2ac1c0a6d2e86f70577662d985ea755707a6855e67bcc0fc1e3d8f89ac563
|
4
|
+
data.tar.gz: 47544f75a230d272e38bd50adacd388d4cb8a8710da689ae24ca0fe187e7d3f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8427b2e5710ccff4f9031adc64b9ad9e3fcdc4dea4565f933dc34b91f72378230b7946e020074832c8e7f44c7c5085bc0c3dc503b98d9852a2fb207b685f41b1
|
7
|
+
data.tar.gz: a8fa9c03c1cfa03947e3be6a35b610192cb2a50f5111f175b3211ee1ca35fcafbc371583c53e3b006735873fd5c07897c8dd3edcf6fb0235fac49353e19a460d
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.2.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lizarb (1.0.
|
4
|
+
lizarb (1.0.2)
|
5
5
|
colorize (~> 0.8)
|
6
6
|
dotenv (~> 2.8)
|
7
7
|
zeitwerk (~> 2.6)
|
@@ -13,7 +13,9 @@ GEM
|
|
13
13
|
colorize (0.8.1)
|
14
14
|
connection_pool (2.3.0)
|
15
15
|
dotenv (2.8.1)
|
16
|
+
htmlbeautifier (1.4.2)
|
16
17
|
method_source (1.0.0)
|
18
|
+
mini_portile2 (2.8.1)
|
17
19
|
nio4r (2.5.8)
|
18
20
|
pry (0.14.1)
|
19
21
|
coderay (~> 1.1)
|
@@ -29,16 +31,17 @@ GEM
|
|
29
31
|
redis-client (>= 0.9.0)
|
30
32
|
redis-client (0.10.0)
|
31
33
|
connection_pool
|
32
|
-
sqlite3 (1.5.
|
33
|
-
|
34
|
+
sqlite3 (1.5.4)
|
35
|
+
mini_portile2 (~> 2.8.0)
|
34
36
|
webrick (1.7.0)
|
35
|
-
zeitwerk (2.6.
|
37
|
+
zeitwerk (2.6.7)
|
36
38
|
|
37
39
|
PLATFORMS
|
38
40
|
arm64-darwin-21
|
39
41
|
x86_64-linux
|
40
42
|
|
41
43
|
DEPENDENCIES
|
44
|
+
htmlbeautifier (~> 1.4)
|
42
45
|
lizarb!
|
43
46
|
pry (~> 0.14.1)
|
44
47
|
puma (~> 5.6)
|
data/README.md
CHANGED
@@ -6,97 +6,56 @@ Liza is a light, experimental framework primarily developed to help study the Ru
|
|
6
6
|
|
7
7
|
Install the gem by executing:
|
8
8
|
|
9
|
-
|
9
|
+
gem install lizarb
|
10
10
|
|
11
11
|
You will get the following three shims:
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
lizarb version
|
14
|
+
liza version
|
15
|
+
lrb version
|
15
16
|
|
16
|
-
##
|
17
|
-
|
18
|
-
Try Liza with an interactive prompt
|
19
|
-
|
20
|
-
$ liza dev
|
21
|
-
|
22
|
-
## Running Tests
|
23
|
-
|
24
|
-
Run your Liza tests
|
25
|
-
|
26
|
-
$ liza test
|
27
|
-
|
28
|
-
## Happy
|
29
|
-
|
30
|
-
Try Liza and build an ASCII game
|
17
|
+
## Create a liza app
|
31
18
|
|
32
|
-
|
19
|
+
So you can run your experiments:
|
33
20
|
|
34
|
-
|
21
|
+
liza new
|
35
22
|
|
36
|
-
|
23
|
+
Then enter your automagically generated liza app:
|
37
24
|
|
38
|
-
|
25
|
+
cd app_1
|
26
|
+
bundle install
|
39
27
|
|
40
|
-
|
28
|
+
Now you're ready to go and try some stuff!
|
41
29
|
|
42
|
-
|
43
|
-
NetBox.clients.get :redis_url
|
44
|
-
|
45
|
-
NetBox.databases.sql
|
46
|
-
NetBox.databases.sqlite
|
47
|
-
NetBox.databases.redis
|
48
|
-
|
49
|
-
RedisDb.current
|
50
|
-
SqliteDb.current
|
51
|
-
|
52
|
-
RedisDb.current.call "TIME"
|
53
|
-
SqliteDb.current.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';"
|
54
|
-
|
55
|
-
```
|
56
|
-
|
57
|
-
## Web Server
|
30
|
+
## Try
|
58
31
|
|
59
|
-
Try Liza with
|
32
|
+
Try Liza with an interactive terminal
|
60
33
|
|
61
|
-
|
34
|
+
liza terminal
|
62
35
|
|
63
|
-
|
64
|
-
|
65
|
-
http://localhost:3000/xxxxxxx
|
66
|
-
|
67
|
-
http://localhost:3000/api/xxxxxxx
|
68
|
-
|
69
|
-
http://localhost:3000/api/auth/sign_up
|
70
|
-
|
71
|
-
http://localhost:3000/api/auth/sign_in
|
72
|
-
|
73
|
-
http://localhost:3000/api/auth/account
|
74
|
-
|
75
|
-
http://localhost:3000/api/auth/sign_out
|
76
|
-
|
77
|
-
http://localhost:3000/assets/app.css
|
78
|
-
|
79
|
-
http://localhost:3000/assets/app.js
|
36
|
+
## Running Tests
|
80
37
|
|
81
|
-
|
38
|
+
Run your Liza tests
|
82
39
|
|
83
|
-
|
40
|
+
liza test
|
84
41
|
|
85
42
|
## Development
|
86
43
|
|
87
44
|
To install dependencies, run this bash script:
|
88
45
|
|
89
|
-
|
46
|
+
bin/setup
|
90
47
|
|
91
48
|
For development experiments, use the local executable script
|
92
49
|
|
93
|
-
|
50
|
+
exe/lizarb test
|
94
51
|
|
95
52
|
To build and install lizarb in your local machine
|
96
53
|
|
97
|
-
|
54
|
+
bundle exec rake install
|
55
|
+
|
56
|
+
For systems in development, see [README_SYSTEMS.md](https://github.com/rubyonrails-brasil/lizarb/blob/master/README_SYSTEMS.md).
|
98
57
|
|
99
|
-
## Release
|
58
|
+
## Release
|
100
59
|
|
101
60
|
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
102
61
|
|
data/README_SYSTEMS.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Liza - Systems in Development
|
2
|
+
|
3
|
+
These systems operate at a very small capacity, and will be fleshed out in the future.
|
4
|
+
|
5
|
+
## Happy
|
6
|
+
|
7
|
+
Try Liza and build an ASCII game
|
8
|
+
|
9
|
+
liza happy axo
|
10
|
+
|
11
|
+
## Networking
|
12
|
+
|
13
|
+
Try Liza to connect with Sqlite and Redis
|
14
|
+
|
15
|
+
liza net
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
|
19
|
+
NetBox.clients.get :sqlite
|
20
|
+
NetBox.clients.get :redis_url
|
21
|
+
|
22
|
+
NetBox.databases.sql
|
23
|
+
NetBox.databases.sqlite
|
24
|
+
NetBox.databases.redis
|
25
|
+
|
26
|
+
RedisDb.current
|
27
|
+
SqliteDb.current
|
28
|
+
|
29
|
+
RedisDb.current.call "TIME"
|
30
|
+
SqliteDb.current.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';"
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
## Rack Web Server
|
35
|
+
|
36
|
+
Try Liza with the Rack Web Server
|
37
|
+
|
38
|
+
liza rack
|
39
|
+
|
40
|
+
http://localhost:3000/
|
41
|
+
|
42
|
+
http://localhost:3000/xxxxxxx
|
43
|
+
|
44
|
+
http://localhost:3000/api/xxxxxxx
|
45
|
+
|
46
|
+
http://localhost:3000/api/auth/sign_up
|
47
|
+
|
48
|
+
http://localhost:3000/api/auth/sign_in
|
49
|
+
|
50
|
+
http://localhost:3000/api/auth/account
|
51
|
+
|
52
|
+
http://localhost:3000/api/auth/sign_out
|
53
|
+
|
54
|
+
http://localhost:3000/assets/app.css
|
55
|
+
|
56
|
+
http://localhost:3000/assets/app.js
|
57
|
+
|
58
|
+
## Web Request
|
59
|
+
|
60
|
+
Try Liza with the Rack Web Server
|
61
|
+
|
62
|
+
liza request get /
|
63
|
+
|
64
|
+
liza request post /
|
65
|
+
|
66
|
+
liza request get /xxxxxxx
|
67
|
+
|
68
|
+
liza request get /api/xxxxxxx
|
69
|
+
|
70
|
+
liza request get /api/auth/sign_up
|
71
|
+
|
72
|
+
liza request get /api/auth/sign_in
|
73
|
+
|
74
|
+
liza request get /api/auth/account
|
75
|
+
|
76
|
+
liza request get /api/auth/sign_out
|
77
|
+
|
78
|
+
liza request get /assets/app.css
|
79
|
+
|
80
|
+
liza request get /assets/app.js
|
data/Rakefile
CHANGED
@@ -70,6 +70,24 @@ class LoopsBench < AppBench
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
mark "HASH_INT.each_pair do |i, iv|" do
|
74
|
+
HASH_INT.each_pair do |i, iv|
|
75
|
+
a = "1"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
mark "HASH_STR.each_pair do |i, iv|" do
|
80
|
+
HASH_STR.each_pair do |i, iv|
|
81
|
+
a = "1"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
mark "HASH_SYM.each_pair do |i, iv|" do
|
86
|
+
HASH_SYM.each_pair do |i, iv|
|
87
|
+
a = "1"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
73
91
|
mark "RANGE.map do |i|" do
|
74
92
|
RANGE.map do |i|
|
75
93
|
a = "1"
|
@@ -112,6 +130,17 @@ class LoopsBench < AppBench
|
|
112
130
|
end
|
113
131
|
end
|
114
132
|
|
133
|
+
mark "1.upto N next" do
|
134
|
+
it = 1.upto N
|
135
|
+
begin
|
136
|
+
it.next while true
|
137
|
+
rescue StopIteration
|
138
|
+
end
|
139
|
+
# do |i|
|
140
|
+
# a = "1"
|
141
|
+
# end
|
142
|
+
end
|
143
|
+
|
115
144
|
mark "loop break" do
|
116
145
|
i = 0
|
117
146
|
|
@@ -129,6 +158,12 @@ class LoopsBench < AppBench
|
|
129
158
|
end
|
130
159
|
end
|
131
160
|
|
161
|
+
mark "while inline" do
|
162
|
+
i = 0
|
163
|
+
|
164
|
+
a = "1" while (i += 1) <= N
|
165
|
+
end
|
166
|
+
|
132
167
|
mark "begin end while" do
|
133
168
|
i = 0
|
134
169
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class CalculatorCommand < NarrativeMethodCommand
|
2
|
+
class Error < Error; end
|
3
|
+
|
4
|
+
def self.sum(a, b)= a + b
|
5
|
+
def self.sub(a, b)= a - b
|
6
|
+
def self.mul(a, b)= a * b
|
7
|
+
def self.div(a, b)= a / b
|
8
|
+
|
9
|
+
# instance methods
|
10
|
+
|
11
|
+
def validate
|
12
|
+
log "Called #{self}.#{__method__}"
|
13
|
+
raise Invalid, "liza calculator 0 + 0" if @args.size != 3
|
14
|
+
|
15
|
+
@a = @args[0].to_f
|
16
|
+
@op = @args[1].to_sym
|
17
|
+
@b = @args[2].to_f
|
18
|
+
|
19
|
+
log "@a = #{@a}"
|
20
|
+
log "@op = #{@op}"
|
21
|
+
log "@b = #{@b}"
|
22
|
+
|
23
|
+
raise Invalid, "#{@op} is not a valid operator" unless [:+, :-, :*, :/].include? @op
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform
|
27
|
+
log "Called #{self}.#{__method__}"
|
28
|
+
@result = \
|
29
|
+
case @op
|
30
|
+
when :+ then self.class.sum(@a, @b)
|
31
|
+
when :- then self.class.sub(@a, @b)
|
32
|
+
when :* then self.class.mul(@a, @b)
|
33
|
+
when :/ then self.class.div(@a, @b)
|
34
|
+
end
|
35
|
+
log "RESULT: #{@result}"
|
36
|
+
log render "success.txt"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
__END__
|
42
|
+
|
43
|
+
# help.txt.erb
|
44
|
+
|
45
|
+
NAME:
|
46
|
+
|
47
|
+
liza calculator
|
48
|
+
|
49
|
+
DESCRIPTION:
|
50
|
+
|
51
|
+
Calculates the result of an arithmetic operation.
|
52
|
+
|
53
|
+
USAGE:
|
54
|
+
|
55
|
+
liza calculator <a> <op> <b>
|
56
|
+
|
57
|
+
where <a> and <b> are numbers and <op> is one of the following operators:
|
58
|
+
|
59
|
+
+ addition
|
60
|
+
- subtraction
|
61
|
+
* multiplication
|
62
|
+
/ division
|
63
|
+
|
64
|
+
EXAMPLES:
|
65
|
+
|
66
|
+
liza calculator 1 + 2
|
67
|
+
liza calculator 3 - 4
|
68
|
+
liza calculator 5 * 6
|
69
|
+
liza calculator 7 / 8
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class CalculatorCommandTest < NarrativeMethodCommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == CalculatorCommand
|
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, :sum do
|
13
|
+
assert subject_class.sum(1, 2) == 3
|
14
|
+
end
|
15
|
+
|
16
|
+
test :subject_class, :sub do
|
17
|
+
assert subject_class.sub(1, 2) == -1
|
18
|
+
end
|
19
|
+
|
20
|
+
test :subject_class, :mul do
|
21
|
+
assert subject_class.mul(1, 2) == 2
|
22
|
+
end
|
23
|
+
|
24
|
+
test :subject_class, :div do
|
25
|
+
assert subject_class.div(10, 2) == 5
|
26
|
+
end
|
27
|
+
|
28
|
+
test :validate, :valid do
|
29
|
+
subject = subject_class.new
|
30
|
+
subject.instance_variable_set :@args, ["1", "+", "2"]
|
31
|
+
subject.validate
|
32
|
+
assert subject.instance_variable_get(:@a) == 1
|
33
|
+
assert subject.instance_variable_get(:@op) == :+
|
34
|
+
assert subject.instance_variable_get(:@b) == 2
|
35
|
+
end
|
36
|
+
|
37
|
+
test :validate, :invalid do
|
38
|
+
subject = subject_class.new
|
39
|
+
subject.instance_variable_set :@args, ["1", "x", "2"]
|
40
|
+
begin
|
41
|
+
subject.validate
|
42
|
+
assert false
|
43
|
+
rescue CalculatorCommand::Invalid
|
44
|
+
assert true
|
45
|
+
else
|
46
|
+
assert false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
test :perform do
|
51
|
+
subject = subject_class.new
|
52
|
+
subject.instance_variable_set :@args, ["1", "+", "2"]
|
53
|
+
subject.validate
|
54
|
+
subject.perform
|
55
|
+
assert subject.instance_variable_get(:@result) == 3
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class CircleCommand < NarrativeMethodCommand
|
2
|
+
class Error < Error; end
|
3
|
+
|
4
|
+
def self.area(radius)
|
5
|
+
log "Called #{self}.#{__method__} with radius #{radius}"
|
6
|
+
log "The answer is #{radius**2}π"
|
7
|
+
Math::PI * radius**2
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.circumference(radius)
|
11
|
+
log "Called #{self}.#{__method__} with radius #{radius}"
|
12
|
+
log "The answer is #{radius * 2}π"
|
13
|
+
2 * Math::PI * radius
|
14
|
+
end
|
15
|
+
|
16
|
+
# instance methods
|
17
|
+
|
18
|
+
def validate
|
19
|
+
log "Called #{self}.#{__method__}"
|
20
|
+
raise Invalid, "liza circle <formula> <radius>" if @args.size != 2
|
21
|
+
raise Invalid, "liza circle <formula> <radius>" if @args[0] != "area" && @args[0] != "circumference"
|
22
|
+
|
23
|
+
@formula = @args[0].to_sym
|
24
|
+
@radius = @args[1].to_f
|
25
|
+
|
26
|
+
log "@formula = #{@formula}"
|
27
|
+
log "@radius = #{@radius}"
|
28
|
+
|
29
|
+
raise Invalid, "radius must be greater than 0" if @radius <= 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def perform
|
33
|
+
log "Called #{self}.#{__method__}"
|
34
|
+
|
35
|
+
@result = \
|
36
|
+
case @formula
|
37
|
+
when :area then self.class.area(@radius)
|
38
|
+
when :circumference then self.class.circumference(@radius)
|
39
|
+
end
|
40
|
+
log "RESULT: #{@result}"
|
41
|
+
log render "success.txt"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
__END__
|
47
|
+
|
48
|
+
# help.txt.erb
|
49
|
+
|
50
|
+
NAME:
|
51
|
+
|
52
|
+
liza circle
|
53
|
+
|
54
|
+
DESCRIPTION:
|
55
|
+
|
56
|
+
Calculates a circle formula based on the radius.
|
57
|
+
|
58
|
+
USAGE:
|
59
|
+
|
60
|
+
liza circle <formula> <radius>
|
61
|
+
|
62
|
+
FORMULAS:
|
63
|
+
|
64
|
+
area - calculates the area of a circle
|
65
|
+
circumference - calculates the circumference of a circle
|
66
|
+
|
67
|
+
EXAMPLES:
|
68
|
+
|
69
|
+
liza circle area 5
|
70
|
+
liza circle circumference 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
|