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,54 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class GeneratorDslMainPart < Liza::Part
|
3
|
+
|
4
|
+
insertion do
|
5
|
+
|
6
|
+
def self.call args
|
7
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
8
|
+
|
9
|
+
name = args.shift || raise("args[0] should contain NAME")
|
10
|
+
name = name.downcase
|
11
|
+
|
12
|
+
memo.each do |label, bl|
|
13
|
+
log "Generating #{label}"
|
14
|
+
g = new label, name, args
|
15
|
+
g.instance_exec &bl
|
16
|
+
g.call
|
17
|
+
end
|
18
|
+
|
19
|
+
puts
|
20
|
+
log "done"
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.memo()= @memo ||= {}
|
24
|
+
|
25
|
+
def self.generate(label, &block)= memo[label] = block
|
26
|
+
|
27
|
+
attr_reader :label, :name, :args
|
28
|
+
|
29
|
+
def initialize label, name, args
|
30
|
+
@label, @name, @args = label, name, args
|
31
|
+
end
|
32
|
+
|
33
|
+
def call
|
34
|
+
TextShell.write "#{folder}/#{filename}", "#{content}\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
%w|folder filename content|.each do |s|
|
38
|
+
class_eval <<-CODE, __FILE__, __LINE__ + 1
|
39
|
+
attr_reader :#{s}
|
40
|
+
|
41
|
+
def #{s} #{s} = nil
|
42
|
+
if #{s}
|
43
|
+
@#{s} = #{s}
|
44
|
+
else
|
45
|
+
@#{s}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
CODE
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class GeneratorTest < Liza::ControllerTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == DevSystem::Generator
|
6
|
+
end
|
7
|
+
|
8
|
+
test :settings do
|
9
|
+
assert subject_class.log_level == :normal
|
10
|
+
assert subject_class.log_color == :green
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class AppGenerator < Generator
|
3
|
+
|
4
|
+
def self.call args
|
5
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
6
|
+
new.call args
|
7
|
+
end
|
8
|
+
|
9
|
+
def call args
|
10
|
+
# setup
|
11
|
+
|
12
|
+
name = args.shift || "app_1"
|
13
|
+
|
14
|
+
from = "#{Lizarb::APP_DIR}/app_new"
|
15
|
+
to = name
|
16
|
+
|
17
|
+
return log "Directory #{to.light_green} already exists." if Dir.exist? to
|
18
|
+
|
19
|
+
log "Liza Application initializing at `#{to}`"
|
20
|
+
|
21
|
+
# init
|
22
|
+
|
23
|
+
require "fileutils"
|
24
|
+
FileUtils.cp_r from, to, verbose: true
|
25
|
+
|
26
|
+
`cd #{to}; git init -b main`
|
27
|
+
|
28
|
+
# extra
|
29
|
+
|
30
|
+
puts
|
31
|
+
|
32
|
+
FileShell.gitkeep "#{to}/lib"
|
33
|
+
FileShell.gitkeep "#{to}/tmp"
|
34
|
+
|
35
|
+
DirShell.create "#{to}/app"
|
36
|
+
|
37
|
+
# systems
|
38
|
+
|
39
|
+
# App.systems.keys.each { |system_name| copy to, system_name }
|
40
|
+
copy to, :dev
|
41
|
+
|
42
|
+
FileUtils.rm "#{to}/app/dev/commands/new_command.rb"
|
43
|
+
FileUtils.rm "#{to}/app/dev/commands/new_command_test.rb"
|
44
|
+
|
45
|
+
`rm -rf #{to}/app/dev/generators/record_generator*`
|
46
|
+
`rm -rf #{to}/app/dev/generators/request_generator*`
|
47
|
+
|
48
|
+
FileUtils.cp_r "#{Lizarb::APP_DIR}/.ruby-version", "#{to}/.ruby-version", verbose: true
|
49
|
+
FileUtils.cp_r "#{Lizarb::APP_DIR}/README.md", "#{to}/README.md", verbose: true
|
50
|
+
TextShell.write "#{to}/app.rb", render("app.rb")
|
51
|
+
FileUtils.cp_r "#{Lizarb::APP_DIR}/app.env", "#{to}/app.env", verbose: true
|
52
|
+
FileUtils.cp_r "#{Lizarb::APP_DIR}/app.code.env", "#{to}/app.code.env", verbose: true
|
53
|
+
|
54
|
+
puts
|
55
|
+
|
56
|
+
log "Liza Application initialized at `#{to}`"
|
57
|
+
end
|
58
|
+
|
59
|
+
def copy name, system_name
|
60
|
+
from = "#{Lizarb::APP_DIR}/app/#{system_name}_box.rb"
|
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
|
67
|
+
|
68
|
+
from = "#{Lizarb::APP_DIR}/app/#{system_name}"
|
69
|
+
to = "#{name}/app"
|
70
|
+
if File.exist? from
|
71
|
+
FileUtils.cp_r from, to, verbose: true
|
72
|
+
else
|
73
|
+
puts "file not found #{from}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
__END__
|
81
|
+
|
82
|
+
# app.rb.erb
|
83
|
+
App.call ARGV do
|
84
|
+
|
85
|
+
# Systems help you organize your application's dependencies and RAM memory usage.
|
86
|
+
# Learn more: http://guides.lizarb.org/systems.html
|
87
|
+
|
88
|
+
system :dev
|
89
|
+
|
90
|
+
# Modes help you organize your application's behavior and settings.
|
91
|
+
# Learn more: http://guides.lizarb.org/modes.html
|
92
|
+
|
93
|
+
mode :code
|
94
|
+
mode :demo
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class AppGeneratorTest < GeneratorTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == DevSystem::AppGenerator
|
6
|
+
end
|
7
|
+
|
8
|
+
test :settings do
|
9
|
+
assert subject_class.log_level == :normal
|
10
|
+
assert subject_class.log_color == :green
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= name.camelize %>Generator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/<%= name %>s"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_<%= name %>.rb"
|
9
|
+
content render "<%= name %>.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_<%= name %>_test.rb"
|
15
|
+
content render "<%= name %>_test.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class <%= name.camelize %>GeneratorTest < Liza::GeneratorTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == <%= name.camelize %>Generator
|
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,12 @@
|
|
1
|
+
class <%%= name.camelize %><%= name.camelize %>Test < Liza::<%= name.camelize %>Test
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == <%%= name.camelize %><%= name.camelize %>
|
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,30 @@
|
|
1
|
+
class DevSystem::GeneratorGenerator < Liza::Generator
|
2
|
+
main_dsl
|
3
|
+
|
4
|
+
FOLDER = "app/dev/generators"
|
5
|
+
|
6
|
+
generate :controller do
|
7
|
+
folder FOLDER
|
8
|
+
filename "#{name}_generator.rb"
|
9
|
+
content render "generator.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
generate :controller_test do
|
13
|
+
folder FOLDER
|
14
|
+
filename "#{name}_generator_test.rb"
|
15
|
+
content render "generator_test.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
generate :template do
|
19
|
+
folder "#{FOLDER}/#{name}_generator"
|
20
|
+
filename "#{name}.rb.erb"
|
21
|
+
content render "template.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
generate :template_test do
|
25
|
+
folder "#{FOLDER}/#{name}_generator"
|
26
|
+
filename "#{name}_test.rb.erb"
|
27
|
+
content render "template_test.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class DevSystem::GeneratorGeneratorTest < Liza::GeneratorTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == DevSystem::GeneratorGenerator
|
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,29 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class NotFoundGenerator < Generator
|
3
|
+
|
4
|
+
def self.call args
|
5
|
+
# 1. LOG
|
6
|
+
|
7
|
+
log :higher, "Called #{self}.#{__method__} with args #{args}"
|
8
|
+
puts
|
9
|
+
|
10
|
+
# 2. FIND generators
|
11
|
+
|
12
|
+
App.eager_load_all
|
13
|
+
generators = Liza::Generator.descendants
|
14
|
+
|
15
|
+
log "Liza comes with #{generators.count} generators you can use."
|
16
|
+
puts
|
17
|
+
|
18
|
+
log "Here they are:"
|
19
|
+
puts
|
20
|
+
|
21
|
+
# 3. LIST generators
|
22
|
+
|
23
|
+
keys = generators.map { |k| k.last_namespace.snakecase[0..-11] }.sort
|
24
|
+
keys.reject! { |s| s == "not_found" }
|
25
|
+
keys.each { |s| log "liza generate #{s}" }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DevSystem
|
2
|
+
class NotFoundGeneratorTest < GeneratorTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == DevSystem::NotFoundGenerator
|
6
|
+
end
|
7
|
+
|
8
|
+
test :settings do
|
9
|
+
assert subject_class.log_level == :normal
|
10
|
+
assert subject_class.log_color == :green
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class DevSystem::BinShell < DevSystem::FileShell
|
2
|
+
|
3
|
+
set :create_dir, true
|
4
|
+
|
5
|
+
def self.read path
|
6
|
+
log "Reading #{path}"
|
7
|
+
_raise_if_blank path
|
8
|
+
_raise_if_not_exists path
|
9
|
+
|
10
|
+
File.binread path
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.write path, content, create_dir: nil
|
14
|
+
log "Writing #{content&.size.to_i} bytes (#{content.encoding}) to #{path}"
|
15
|
+
_raise_if_blank path
|
16
|
+
|
17
|
+
create_dir = get :create_dir if create_dir.nil?
|
18
|
+
DevSystem::DirShell.create File.dirname path if create_dir
|
19
|
+
|
20
|
+
File.binwrite path, content
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class DevSystem::BinShellTest < DevSystem::FileShellTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == DevSystem::BinShell
|
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
|
+
#
|
13
|
+
|
14
|
+
test :subject_class, :read, :raise do
|
15
|
+
assert_raises ArgumentError do
|
16
|
+
subject_class.read nil
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_raises ArgumentError do
|
20
|
+
subject_class.read ""
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_raises ArgumentError do
|
24
|
+
subject_class.read "does_not_exist_#{rand 999}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
test :subject_class, :read, true do
|
29
|
+
assert subject_class.read(__FILE__).size.positive?
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
|
34
|
+
test :subject_class, :write, :raise do
|
35
|
+
assert_raises ArgumentError do
|
36
|
+
subject_class.write nil, "content"
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raises ArgumentError do
|
40
|
+
subject_class.write "", "content"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test :subject_class, :write, true do
|
45
|
+
path = tmp_dir.join "write_#{Time.now.to_i}"
|
46
|
+
|
47
|
+
refute subject_class.exist? path
|
48
|
+
assert subject_class.write path, "content"
|
49
|
+
|
50
|
+
assert subject_class.exist? path
|
51
|
+
assert subject_class.read(path) == "content"
|
52
|
+
end
|
53
|
+
|
54
|
+
test :subject_class, :write, :encoding do
|
55
|
+
path = tmp_dir.join "write_#{Time.now.to_i}"
|
56
|
+
s1 = "content"
|
57
|
+
|
58
|
+
refute subject_class.exist? path
|
59
|
+
assert subject_class.write path, s1
|
60
|
+
|
61
|
+
s2 = subject_class.read path
|
62
|
+
assert_equality s1, s2
|
63
|
+
refute_equality s1.encoding, s2.encoding
|
64
|
+
|
65
|
+
assert_equality s1.encoding, Encoding::UTF_8
|
66
|
+
assert_equality s2.encoding, Encoding::ASCII_8BIT
|
67
|
+
end
|
68
|
+
|
69
|
+
test :subject_class, :write, :create_dir do
|
70
|
+
path = tmp_dir.join "write_dir_#{Time.now.to_i}/a/b/c"
|
71
|
+
|
72
|
+
refute subject_class.exist? path
|
73
|
+
|
74
|
+
assert_raises Errno::ENOENT do
|
75
|
+
assert subject_class.write path, "content", create_dir: false
|
76
|
+
end
|
77
|
+
|
78
|
+
refute subject_class.exist? path
|
79
|
+
|
80
|
+
refute_raises Errno::ENOENT do
|
81
|
+
assert subject_class.write path, "content", create_dir: true
|
82
|
+
end
|
83
|
+
|
84
|
+
assert subject_class.exist? path
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class DevSystem::DirShell < DevSystem::FileShell
|
2
|
+
|
3
|
+
# OVERRIDES
|
4
|
+
|
5
|
+
def self.exist? path
|
6
|
+
log :normal, "Checking if directory exists at '#{path}'"
|
7
|
+
|
8
|
+
directory? path
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.size path
|
12
|
+
log :normal, "Getting size of directory at '#{path}'"
|
13
|
+
_raise_if_not_exists path
|
14
|
+
|
15
|
+
Pathname.new(path).children.inject(0) { |sum, f| sum + f.size }
|
16
|
+
end
|
17
|
+
|
18
|
+
# CUSTOM
|
19
|
+
|
20
|
+
def self.create path
|
21
|
+
log :normal, "Creating directory at '#{path}'"
|
22
|
+
_raise_if_blank path
|
23
|
+
|
24
|
+
Pathname.new(path).mkpath
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class DevSystem::DirShellTest < DevSystem::FileShellTest
|
2
|
+
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == DevSystem::DirShell
|
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
|
+
#
|
13
|
+
|
14
|
+
test :subject_class, :exist?, :raise do
|
15
|
+
assert_raises ArgumentError do
|
16
|
+
subject_class.exist? nil
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_raises ArgumentError do
|
20
|
+
subject_class.exist? ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test :subject_class, :exist?, true do
|
25
|
+
assert subject_class.exist? Dir.pwd
|
26
|
+
assert subject_class.exist? Liza::Shell.source_location_radical
|
27
|
+
end
|
28
|
+
|
29
|
+
test :subject_class, :exist?, false do
|
30
|
+
refute subject_class.exist? "does_not_exist"
|
31
|
+
refute subject_class.exist? Liza::DirShell.source_location_radical
|
32
|
+
end
|
33
|
+
|
34
|
+
test :subject_class, :size, :raise do
|
35
|
+
assert_raises ArgumentError do
|
36
|
+
subject_class.size nil
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_raises ArgumentError do
|
40
|
+
subject_class.size ""
|
41
|
+
end
|
42
|
+
|
43
|
+
assert_raises ArgumentError do
|
44
|
+
subject_class.size "does_not_exist"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test :subject_class, :size, true do
|
49
|
+
assert subject_class.size(Dir.pwd).positive?
|
50
|
+
assert subject_class.size(Liza::Shell.source_location_radical).positive?
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
|
55
|
+
test :subject_class, :create, :raise do
|
56
|
+
assert_raises ArgumentError do
|
57
|
+
subject_class.create nil
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_raises ArgumentError do
|
61
|
+
subject_class.create ""
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
test :subject_class, :create, true do
|
66
|
+
path = tmp_dir.join "create_#{Time.now.to_i}"
|
67
|
+
refute subject_class.exist? path
|
68
|
+
|
69
|
+
subject_class.create path
|
70
|
+
assert subject_class.exist? path
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class DevSystem::FileShell < DevSystem::Shell
|
2
|
+
|
3
|
+
def self._raise_if_blank path
|
4
|
+
raise ArgumentError, "Path is required" if path.nil? || path.to_s.empty?
|
5
|
+
end
|
6
|
+
|
7
|
+
def self._raise_if_not_exists path
|
8
|
+
raise ArgumentError, "File does not exist at '#{path}'" unless exist? path
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
|
13
|
+
def self.exist? path
|
14
|
+
log :normal, "Checking if file exists at '#{path}'"
|
15
|
+
_raise_if_blank path
|
16
|
+
|
17
|
+
File.exist? path
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.size path
|
21
|
+
log :normal, "Getting size of file at '#{path}'"
|
22
|
+
_raise_if_not_exists path
|
23
|
+
|
24
|
+
File.size path
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
|
29
|
+
def self.directory? path
|
30
|
+
log :normal, "Checking if '#{path}' is a directory"
|
31
|
+
_raise_if_blank path
|
32
|
+
|
33
|
+
File.directory? path
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.file? path
|
37
|
+
log :normal, "Checking if '#{path}' is a file"
|
38
|
+
_raise_if_blank path
|
39
|
+
|
40
|
+
File.file? path
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
|
45
|
+
def self.touch path
|
46
|
+
log :normal, "Touching '#{path}'"
|
47
|
+
_raise_if_blank path
|
48
|
+
|
49
|
+
dir = File.dirname(path)
|
50
|
+
DevSystem::DirShell.create dir
|
51
|
+
|
52
|
+
FileUtils.touch path
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.gitkeep path
|
56
|
+
touch "#{path}/.gitkeep"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|