lizarb 0 → 1.0.1
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 -0
- data/CHANGELOG.md +13 -2
- data/Gemfile +22 -2
- data/Gemfile.lock +52 -0
- data/README.md +88 -12
- 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 +148 -0
- data/app/dev/benches/loops_bench_test.rb +11 -0
- data/app/dev/commands/app_command.rb +5 -0
- data/app/dev/commands/app_command_test.rb +7 -0
- data/app/dev/commands/example_command.rb +57 -0
- data/app/dev/commands/example_command_test.rb +43 -0
- data/app/dev/commands/macro_child_command.rb +32 -0
- data/app/dev/commands/macro_child_command_test.rb +7 -0
- data/app/dev/commands/macro_parent_command.rb +70 -0
- data/app/dev/commands/macro_parent_command_test.rb +7 -0
- data/app/dev/commands/my_command.rb +7 -0
- data/app/dev/commands/my_command_test.rb +7 -0
- data/app/dev/commands/new_command.rb +9 -0
- data/app/dev/commands/new_command_test.rb +7 -0
- data/app/dev/generators/bench_generator.rb +67 -0
- data/app/dev/generators/bench_generator_test.rb +12 -0
- data/app/dev/generators/command_generator.rb +51 -0
- data/app/dev/generators/command_generator_test.rb +12 -0
- data/app/dev/generators/model_generator.rb +46 -0
- data/app/dev/generators/model_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/dev_box.rb +13 -0
- data/app/happy/axos/axo.rb +50 -0
- data/app/happy_box.rb +8 -0
- data/app/net/databases/redis_db.rb +5 -0
- data/app/net/databases/redis_db_test.rb +12 -0
- data/app/net/databases/sqlite_db.rb +11 -0
- data/app/net/databases/sqlite_db_test.rb +12 -0
- data/app/net/models/app_model.rb +20 -0
- data/app/net/models/app_model_test.rb +8 -0
- data/app/net/models/post_model.rb +4 -0
- data/app/net/models/post_model_test.rb +8 -0
- data/app/net/models/user_model.rb +4 -0
- data/app/net/models/user_model_test.rb +8 -0
- data/app/net_box.rb +21 -0
- data/app/web/requests/api_request.rb +61 -0
- data/app/web/requests/api_request_test.rb +31 -0
- data/app/web/requests/app_request.rb +5 -0
- data/app/web/requests/app_request_test.rb +7 -0
- data/app/web/requests/assets_request.rb +71 -0
- data/app/web/requests/assets_request_test.rb +33 -0
- data/app/web/requests/root_request.rb +55 -0
- data/app/web/requests/root_request_test.rb +31 -0
- data/app/web_box.rb +8 -0
- data/app.code.env +11 -0
- data/app.env +11 -0
- data/app.rb +17 -0
- data/app_new/.gitignore +4 -0
- data/app_new/Gemfile +31 -0
- data/app_new/Procfile +3 -0
- data/exe/Gemfile +3 -0
- data/exe/Gemfile.lock +13 -0
- data/exe/liza +3 -0
- data/exe/lizarb +11 -0
- data/lib/app.rb +200 -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/bench_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/dev_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
- data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
- data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
- data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command.rb +19 -0
- data/lib/dev_system/dev/controllers/command_test.rb +14 -0
- 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 +71 -0
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell.rb +19 -0
- data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
- data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
- 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 +22 -0
- data/lib/dev_system/dev/dev_box_test.rb +19 -0
- data/lib/dev_system/dev/panels/command_panel.rb +10 -0
- data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
- data/lib/dev_system/dev/panels/log_panel.rb +10 -0
- data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
- data/lib/dev_system.rb +8 -0
- data/lib/happy_system/dev/happy_command.rb +11 -0
- data/lib/happy_system/happy/controllers/axo.rb +8 -0
- data/lib/happy_system/happy/happy_box.rb +12 -0
- data/lib/happy_system/happy/happy_box_test.rb +18 -0
- data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
- data/lib/{viral.rb → happy_system.rb} +7 -3
- data/lib/liza/base/box.rb +40 -0
- data/lib/liza/base/box_test.rb +12 -0
- data/lib/liza/base/controller.rb +27 -0
- data/lib/liza/base/controller_test.rb +12 -0
- data/lib/liza/base/panel.rb +38 -0
- data/lib/liza/base/panel_test.rb +16 -0
- data/lib/liza/meta/part.rb +19 -0
- data/lib/liza/meta/part_extension.rb +13 -0
- data/lib/liza/meta/part_test.rb +8 -0
- data/lib/liza/meta/system.rb +20 -0
- data/lib/liza/meta/system_test.rb +13 -0
- data/lib/liza/test/test.rb +11 -0
- data/lib/liza/test/test_test.rb +108 -0
- data/lib/liza/test_parts/test_assertions_part.rb +110 -0
- data/lib/liza/test_parts/test_context_part.rb +81 -0
- data/lib/liza/test_parts/test_dsl_part.rb +122 -0
- data/lib/liza/test_parts/test_subject_part.rb +24 -0
- data/lib/liza/unit.rb +149 -0
- data/lib/liza/unit_test.rb +79 -0
- data/lib/liza.rb +62 -0
- data/lib/lizarb/ruby/class.rb +17 -0
- data/lib/lizarb/ruby/proc.rb +12 -0
- data/lib/lizarb/ruby/string.rb +25 -0
- data/lib/lizarb/ruby/time.rb +9 -0
- data/lib/{viral → lizarb}/version.rb +2 -2
- data/lib/lizarb.rb +68 -0
- data/lib/net_system/dev/net_command.rb +24 -0
- data/lib/net_system/net/controllers/client/redis_client.rb +28 -0
- data/lib/net_system/net/controllers/client/redis_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client/sqlite_client.rb +28 -0
- data/lib/net_system/net/controllers/client/sqlite_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client.rb +5 -0
- data/lib/net_system/net/controllers/client_test.rb +14 -0
- data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
- data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database.rb +33 -0
- data/lib/net_system/net/controllers/database_test.rb +14 -0
- data/lib/net_system/net/controllers/model.rb +31 -0
- data/lib/net_system/net/controllers/model_test.rb +14 -0
- data/lib/net_system/net/net_box.rb +20 -0
- data/lib/net_system/net/net_box_test.rb +19 -0
- data/lib/net_system/net/panels/client_panel.rb +5 -0
- data/lib/net_system/net/panels/client_panel_test.rb +18 -0
- data/lib/net_system/net/panels/database_panel.rb +12 -0
- data/lib/net_system/net/panels/database_panel_test.rb +18 -0
- data/lib/net_system.rb +3 -0
- data/lib/web_system/dev/web_command.rb +42 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
- data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
- data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
- data/lib/web_system/web/controllers/request.rb +5 -0
- data/lib/web_system/web/controllers/request_test.rb +18 -0
- data/lib/web_system/web/panels/request_panel.rb +55 -0
- data/lib/web_system/web/panels/request_panel_test.rb +14 -0
- data/lib/web_system/web/web_box.rb +12 -0
- data/lib/web_system/web/web_box_test.rb +18 -0
- data/lib/web_system.rb +5 -0
- data/lizarb.gemspec +44 -0
- data/sig/{viral.rbs → lizarb.rbs} +1 -1
- data/tmp/.gitkeep +0 -0
- data/web_files/favicon.ico +0 -0
- data/web_files/favicon.svg +948 -0
- metadata +226 -13
- data/viral.gemspec +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4e73803f6fe207c86ff2e6799e3bdbe50979bbe9fb409750c067ef6ce299c5b
|
4
|
+
data.tar.gz: 46c590ae60a43c0fd0b901f800da5f8761cc70baae0ace96e64a772941c6512f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c83f9babff78a0487784c8c62bf98cf3dd44e64a01267c57bcb1bd4938c980ec09759f4069ef6819088511e25ef6e29f6acc3920ae950c71d00e43d362970c9
|
7
|
+
data.tar.gz: 043bbe7ac4dc5102f3a2b8b261ff13e7a8784d6217a5474b40d8110005b4060d281cf73f938172e0487564c80427d7f63f3e2c1df6c9a3b252f6fd214052070a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.1.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
-
|
3
|
+
-
|
4
4
|
|
5
|
-
-
|
5
|
+
## [1.0.0] - 2022-10-11
|
6
|
+
|
7
|
+
- App, Liza and Lizarb
|
8
|
+
- Liza::Unit, Liza::Part
|
9
|
+
- Liza::Test
|
10
|
+
- Liza::Unit has class/instance methods settings/set/set/add/fetch
|
11
|
+
- Liza::Unit has class/instance methods log/log_color/log_level/log?/log_level?
|
12
|
+
- Liza::System, Liza::Box, Liza::Panel, Liza::Controller
|
13
|
+
- DevSystem, Liza::DevBox, Liza::Command, AppCommand, and others
|
14
|
+
- HappySystem, Liza::HappyBox, Liza::Axo, Axo, and others
|
15
|
+
- NetSystem, Liza::NetBox, Liza::Adapter, Liza::Database, Liza::Model, AppModel, and others
|
16
|
+
- WebSystem, Liza::WebBox, Liza::Request, AppRequest, and others
|
data/Gemfile
CHANGED
@@ -2,7 +2,27 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
# Specify your gem's dependencies in
|
5
|
+
# Specify your gem's dependencies in lizarb.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
|
8
|
+
group :dev do
|
9
|
+
# gems you only want to load if DevSystem is loaded
|
10
|
+
gem "pry", "~> 0.14.1"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :happy do
|
14
|
+
# gems you only want to load if HappySystem is loaded
|
15
|
+
end
|
16
|
+
|
17
|
+
group :net do
|
18
|
+
# gems you only want to load if NetSystem is loaded
|
19
|
+
gem "redis", "~> 5.0"
|
20
|
+
gem "sqlite3", "~> 1.5"
|
21
|
+
end
|
22
|
+
|
23
|
+
group :web do
|
24
|
+
# gems you only want to load if WebSystem is loaded
|
25
|
+
gem "rack", "~> 3.0"
|
26
|
+
gem "rackup", "~> 0.2.2"
|
27
|
+
gem "puma", "~> 5.6"
|
28
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lizarb (1.0.1)
|
5
|
+
colorize (~> 0.8)
|
6
|
+
dotenv (~> 2.8)
|
7
|
+
zeitwerk (~> 2.6)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.3)
|
13
|
+
colorize (0.8.1)
|
14
|
+
connection_pool (2.3.0)
|
15
|
+
dotenv (2.8.1)
|
16
|
+
method_source (1.0.0)
|
17
|
+
nio4r (2.5.8)
|
18
|
+
pry (0.14.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
puma (5.6.5)
|
22
|
+
nio4r (~> 2.0)
|
23
|
+
rack (3.0.0)
|
24
|
+
rackup (0.2.2)
|
25
|
+
rack (>= 3.0.0.beta1)
|
26
|
+
webrick
|
27
|
+
rake (13.0.6)
|
28
|
+
redis (5.0.5)
|
29
|
+
redis-client (>= 0.9.0)
|
30
|
+
redis-client (0.10.0)
|
31
|
+
connection_pool
|
32
|
+
sqlite3 (1.5.3-arm64-darwin)
|
33
|
+
sqlite3 (1.5.3-x86_64-linux)
|
34
|
+
webrick (1.7.0)
|
35
|
+
zeitwerk (2.6.1)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
arm64-darwin-21
|
39
|
+
x86_64-linux
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
lizarb!
|
43
|
+
pry (~> 0.14.1)
|
44
|
+
puma (~> 5.6)
|
45
|
+
rack (~> 3.0)
|
46
|
+
rackup (~> 0.2.2)
|
47
|
+
rake (~> 13.0)
|
48
|
+
redis (~> 5.0)
|
49
|
+
sqlite3 (~> 1.5)
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
2.3.22
|
data/README.md
CHANGED
@@ -1,18 +1,82 @@
|
|
1
|
-
#
|
1
|
+
# Liza
|
2
2
|
|
3
|
-
|
3
|
+
Liza is a light, experimental framework primarily developed to help study the Ruby language and the Ruby ecosystem.
|
4
4
|
|
5
|
-
|
5
|
+
## Install
|
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
|
-
|
13
|
+
$ lizarb version
|
14
|
+
$ liza version
|
14
15
|
|
15
|
-
|
16
|
+
## Try
|
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
|
31
|
+
|
32
|
+
$ liza happy axo
|
33
|
+
|
34
|
+
## Networking
|
35
|
+
|
36
|
+
Try Liza to connect with Sqlite and Redis
|
37
|
+
|
38
|
+
$ liza net
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
|
42
|
+
NetBox.clients.get :sqlite
|
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
|
58
|
+
|
59
|
+
Try Liza with the Rack Web Server
|
60
|
+
|
61
|
+
$ liza web
|
62
|
+
|
63
|
+
http://localhost:3000/
|
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
|
16
80
|
|
17
81
|
## Usage
|
18
82
|
|
@@ -20,13 +84,25 @@ TODO: Write usage instructions here
|
|
20
84
|
|
21
85
|
## Development
|
22
86
|
|
23
|
-
|
87
|
+
To install dependencies, run this bash script:
|
88
|
+
|
89
|
+
$ bin/setup
|
90
|
+
|
91
|
+
For development experiments, use the local executable script
|
92
|
+
|
93
|
+
$ exe/lizarb test
|
94
|
+
|
95
|
+
To build and install lizarb in your local machine
|
96
|
+
|
97
|
+
$ bundle exec rake install
|
98
|
+
|
99
|
+
## Release
|
24
100
|
|
25
|
-
To
|
101
|
+
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).
|
26
102
|
|
27
103
|
## Contributing
|
28
104
|
|
29
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
105
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubyonrails-brasil/lizarb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rubyonrails-brasil/lizarb/blob/master/CODE_OF_CONDUCT.md).
|
30
106
|
|
31
107
|
## License
|
32
108
|
|
@@ -34,4 +110,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
34
110
|
|
35
111
|
## Code of Conduct
|
36
112
|
|
37
|
-
Everyone interacting in the
|
113
|
+
Everyone interacting in the Lizarb project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rubyonrails-brasil/lizarb/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,148 @@
|
|
1
|
+
class LoopsBench < AppBench
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
setup do
|
5
|
+
N = 1_000_000
|
6
|
+
RANGE = 1..N
|
7
|
+
ARRAY = Array RANGE
|
8
|
+
HASH_INT = RANGE.map { |i| [i, i] }.to_h
|
9
|
+
HASH_STR = RANGE.map { |i| ["a#{i}", i] }.to_h
|
10
|
+
HASH_SYM = RANGE.map { |i| [:"a#{i}", i] }.to_h
|
11
|
+
end
|
12
|
+
|
13
|
+
mark "for i in RANGE" do
|
14
|
+
for i in RANGE
|
15
|
+
a = "1"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
mark "for i in ARRAY" do
|
20
|
+
for i in ARRAY
|
21
|
+
a = "1"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
mark "for i, iv in HASH_INT" do
|
26
|
+
for i, iv in HASH_INT
|
27
|
+
a = "1"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
mark "for i, iv in HASH_STR" do
|
32
|
+
for i, iv in HASH_STR
|
33
|
+
a = "1"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
mark "for i, iv in HASH_SYM" do
|
38
|
+
for i, iv in HASH_SYM
|
39
|
+
a = "1"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
mark "RANGE.each do |i|" do
|
44
|
+
RANGE.each do |i|
|
45
|
+
a = "1"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
mark "ARRAY.each do |i|" do
|
50
|
+
ARRAY.each do |i|
|
51
|
+
a = "1"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
mark "HASH_INT.each do |i, iv|" do
|
56
|
+
HASH_INT.each do |i, iv|
|
57
|
+
a = "1"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
mark "HASH_STR.each do |i, iv|" do
|
62
|
+
HASH_STR.each do |i, iv|
|
63
|
+
a = "1"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
mark "HASH_SYM.each do |i, iv|" do
|
68
|
+
HASH_SYM.each do |i, iv|
|
69
|
+
a = "1"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
mark "RANGE.map do |i|" do
|
74
|
+
RANGE.map do |i|
|
75
|
+
a = "1"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
mark "ARRAY.map do |i|" do
|
80
|
+
ARRAY.map do |i|
|
81
|
+
a = "1"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
mark "HASH_INT.map do |i, iv|" do
|
86
|
+
HASH_INT.map do |i, iv|
|
87
|
+
a = "1"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
mark "HASH_STR.map do |i, iv|" do
|
92
|
+
HASH_STR.map do |i, iv|
|
93
|
+
a = "1"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
mark "HASH_SYM.map do |i, iv|" do
|
98
|
+
HASH_SYM.map do |i, iv|
|
99
|
+
a = "1"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
mark "N.times do |i|" do
|
104
|
+
N.times do |i|
|
105
|
+
a = "1"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
mark "1.upto N do |i|" do
|
110
|
+
1.upto N do |i|
|
111
|
+
a = "1"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
mark "loop break" do
|
116
|
+
i = 0
|
117
|
+
|
118
|
+
loop do
|
119
|
+
a = "1"
|
120
|
+
break unless (i += 1) <= N
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
mark "while" do
|
125
|
+
i = 0
|
126
|
+
|
127
|
+
while (i += 1) <= N
|
128
|
+
a = "1"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
mark "begin end while" do
|
133
|
+
i = 0
|
134
|
+
|
135
|
+
begin
|
136
|
+
a = "1"
|
137
|
+
end while (i += 1) <= N
|
138
|
+
end
|
139
|
+
|
140
|
+
mark "begin end until" do
|
141
|
+
i = 0
|
142
|
+
|
143
|
+
begin
|
144
|
+
a = "1"
|
145
|
+
end until (i += 1) == N
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class ExampleCommand < AppCommand
|
2
|
+
|
3
|
+
def self.call(args)
|
4
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
5
|
+
|
6
|
+
class_helper_method_1(args)
|
7
|
+
class_helper_method_2(args)
|
8
|
+
class_helper_method_3(args)
|
9
|
+
|
10
|
+
command = new(args)
|
11
|
+
command.helper_method_1(args)
|
12
|
+
command.helper_method_2(args)
|
13
|
+
command.helper_method_3(args)
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
|
18
|
+
def self.class_helper_method_1(args)
|
19
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
20
|
+
1
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.class_helper_method_2(args)
|
24
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
25
|
+
2
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.class_helper_method_3(args)
|
29
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
30
|
+
3
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
|
35
|
+
def initialize(args)
|
36
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
37
|
+
@init_args = args
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
|
42
|
+
def helper_method_1(args)
|
43
|
+
log :higher, "Called #{self}.#{__method__} (which has @init_args #{@init_args}) with args #{args}"
|
44
|
+
@init_args[0]
|
45
|
+
end
|
46
|
+
|
47
|
+
def helper_method_2(args)
|
48
|
+
log :higher, "Called #{self}.#{__method__} (which has @init_args #{@init_args}) with args #{args}"
|
49
|
+
@init_args[1]
|
50
|
+
end
|
51
|
+
|
52
|
+
def helper_method_3(args)
|
53
|
+
log :higher, "Called #{self}.#{__method__} (which has @init_args #{@init_args}) with args #{args}"
|
54
|
+
@init_args[2]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class ExampleCommandTest < AppCommandTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == ExampleCommand
|
5
|
+
end
|
6
|
+
|
7
|
+
group "class methods" do
|
8
|
+
|
9
|
+
test :class_helper_method_1 do
|
10
|
+
assert subject_class.class_helper_method_1([]) == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
test :class_helper_method_2 do
|
14
|
+
assert subject_class.class_helper_method_2([]) == 2
|
15
|
+
end
|
16
|
+
|
17
|
+
test :class_helper_method_3 do
|
18
|
+
assert subject_class.class_helper_method_3([]) == 3
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
group "instance methods" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
@subject = subject_class.new([1, 2, 3])
|
27
|
+
end
|
28
|
+
|
29
|
+
test :helper_method_1 do
|
30
|
+
assert @subject.helper_method_1([]) == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
test :helper_method_2 do
|
34
|
+
assert @subject.helper_method_2([]) == 2
|
35
|
+
end
|
36
|
+
|
37
|
+
test :helper_method_3 do
|
38
|
+
assert @subject.helper_method_3([]) == 3
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class MacroChildCommand < MacroParentCommand
|
2
|
+
|
3
|
+
class_macro_method_1 :important_thing
|
4
|
+
class_macro_method_2 :other_thing
|
5
|
+
class_macro_method_3 :other_important_thing
|
6
|
+
class_macro_method_4 :ruby_is_awesome
|
7
|
+
|
8
|
+
#
|
9
|
+
|
10
|
+
def call(args)
|
11
|
+
log :higher, "Called #{self}.#{__method__} (which has @init_args #{@init_args}) with args #{args}"
|
12
|
+
|
13
|
+
if @@class_macro_3
|
14
|
+
@result << :YES_from_instance_call
|
15
|
+
else
|
16
|
+
@result << :NO_from_instance_call
|
17
|
+
end
|
18
|
+
|
19
|
+
@result << helper_method(args)
|
20
|
+
end
|
21
|
+
|
22
|
+
def helper_method(args)
|
23
|
+
log :higher, "Called #{self}.#{__method__} (which has @init_args #{@init_args}) with args #{args}"
|
24
|
+
|
25
|
+
if @@class_macro_4
|
26
|
+
:Yes_from_helper_method
|
27
|
+
else
|
28
|
+
:No_from_helper_method
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class MacroParentCommand < AppCommand
|
2
|
+
|
3
|
+
def self.class_macro_method_1(arg)
|
4
|
+
log :higher, "Called #{self}.#{__method__} with arg #{arg}"
|
5
|
+
@@class_macro_1 = arg
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.class_macro_method_2(arg)
|
9
|
+
log :higher, "Called #{self}.#{__method__} with arg #{arg}"
|
10
|
+
@@class_macro_2 = arg
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.class_macro_method_3(arg)
|
14
|
+
log :higher, "Called #{self}.#{__method__} with arg #{arg}"
|
15
|
+
@@class_macro_3 = arg
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.class_macro_method_4(arg)
|
19
|
+
log :higher, "Called #{self}.#{__method__} with arg #{arg}"
|
20
|
+
@@class_macro_4 = arg
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
|
25
|
+
def self.call(args)
|
26
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
27
|
+
|
28
|
+
if @@class_macro_1
|
29
|
+
args << :yes_from_class_call
|
30
|
+
else
|
31
|
+
args << :no_from_class_call
|
32
|
+
end
|
33
|
+
|
34
|
+
command = new(args)
|
35
|
+
result = command.call(args)
|
36
|
+
|
37
|
+
puts <<-OUTPUT
|
38
|
+
|
39
|
+
self: #{self}
|
40
|
+
args: #{args}
|
41
|
+
command: #{command}
|
42
|
+
result: #{result}
|
43
|
+
|
44
|
+
OUTPUT
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
|
49
|
+
attr_reader :result
|
50
|
+
|
51
|
+
def initialize(args)
|
52
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
53
|
+
@init_args = args
|
54
|
+
|
55
|
+
@result = [args]
|
56
|
+
|
57
|
+
if @@class_macro_2
|
58
|
+
@result << :yes_from_initialize
|
59
|
+
else
|
60
|
+
@result << :no_from_initialize
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
|
66
|
+
def call(args)
|
67
|
+
raise NotImplementedError, "implement this on MacroChildCommand"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|