lizarb 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -13
  3. data/Rakefile +38 -0
  4. data/app/dev_box.rb +14 -12
  5. data/app/happy_box.rb +2 -2
  6. data/app/net_box.rb +4 -4
  7. data/app/web_box.rb +4 -4
  8. data/app.rb +6 -7
  9. data/{exe/Gemfile → app_global.gemfile.rb} +2 -0
  10. data/app_global.gemfile.rb.lock +19 -0
  11. data/app_global.rb +4 -0
  12. data/{app → app_new}/dev/benches/loops_bench.rb +3 -2
  13. data/{app/dev/generators/bench_generator_test.rb → app_new/dev/benches/loops_bench_test.rb} +2 -2
  14. data/app_new/dev/benches/objects_bench.rb +83 -0
  15. data/{app/dev/generators/record_generator_test.rb → app_new/dev/benches/objects_bench_test.rb} +2 -2
  16. data/app_new/dev/benches/sorted_bench.rb +54 -0
  17. data/app_new/dev/benches/sorted_bench_test.rb +12 -0
  18. data/app_new/dev/benches/variables_bench.rb +55 -0
  19. data/{app/dev/generators/command_generator_test.rb → app_new/dev/benches/variables_bench_test.rb} +2 -2
  20. data/{app → app_new}/dev/commands/calculator_command.rb +1 -1
  21. data/{app → app_new}/dev/commands/circle_command.rb +1 -1
  22. data/{app → app_new}/dev/commands/narrative_method_command.rb +5 -7
  23. data/{app → app_new}/dev/commands/quadratic_command.rb +1 -1
  24. data/app_new/dev_box.rb +14 -0
  25. data/app_new.rb +15 -0
  26. data/exe/lizarb +9 -1
  27. data/lib/app.rb +27 -95
  28. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +15 -8
  29. data/lib/dev_system/dev/controllers/bench.rb +0 -6
  30. data/lib/dev_system/dev/controllers/command/bench_command.rb +1 -2
  31. data/lib/dev_system/dev/controllers/command/generate_command.rb +3 -27
  32. data/lib/dev_system/dev/controllers/command/new_command.rb +9 -0
  33. data/lib/dev_system/dev/controllers/command/new_command_test.rb +7 -0
  34. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -8
  35. data/lib/dev_system/dev/controllers/command/terminal_command.rb +2 -2
  36. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -6
  37. data/lib/dev_system/dev/controllers/command.rb +9 -13
  38. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +2 -4
  39. data/{app/dev/generators/bench_generator/bench.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller.rb.erb} +1 -2
  40. data/{app/dev/generators/bench_generator/bench_test.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller_test.rb.erb} +2 -2
  41. data/lib/dev_system/dev/controllers/generators/bench_generator.rb +12 -0
  42. data/lib/dev_system/dev/controllers/generators/bench_generator_test.rb +12 -0
  43. data/lib/dev_system/dev/controllers/generators/command_generator/controller.rb.erb +41 -0
  44. data/{app/dev/generators/command_generator/command_test.rb.erb → lib/dev_system/dev/controllers/generators/command_generator/controller_test.rb.erb} +2 -2
  45. data/lib/dev_system/dev/controllers/generators/command_generator.rb +19 -0
  46. data/lib/dev_system/dev/controllers/generators/command_generator_test.rb +12 -0
  47. data/lib/dev_system/dev/controllers/generators/controller_generator.rb +97 -0
  48. data/lib/dev_system/dev/controllers/generators/controller_generator_test.rb +12 -0
  49. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +1 -1
  50. data/lib/dev_system/dev/controllers/generators/new_generator.rb +117 -0
  51. data/lib/dev_system/dev/controllers/generators/new_generator_test.rb +12 -0
  52. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +20 -8
  53. data/{app/dev → lib/dev_system/dev/controllers}/generators/record_generator.rb +1 -1
  54. data/lib/dev_system/dev/controllers/generators/record_generator_test.rb +12 -0
  55. data/{app/dev → lib/dev_system/dev/controllers}/generators/request_generator.rb +2 -2
  56. data/lib/dev_system/dev/controllers/generators/request_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/log.rb +3 -0
  58. data/{app/dev/generators/request_generator_test.rb → lib/dev_system/dev/controllers/log_test.rb} +2 -2
  59. data/lib/dev_system/dev/controllers/shell.rb +22 -0
  60. data/lib/dev_system/dev/controllers/shell_test.rb +25 -0
  61. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +7 -1
  62. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +1 -1
  63. data/lib/dev_system/dev/dev_box.rb +12 -18
  64. data/lib/dev_system/dev/panels/command_panel.rb +54 -11
  65. data/lib/dev_system/dev/panels/command_panel_test.rb +35 -10
  66. data/lib/dev_system/dev/panels/generator_panel.rb +70 -0
  67. data/lib/dev_system/dev/panels/generator_panel_test.rb +34 -0
  68. data/lib/happy_system/happy/happy_box.rb +2 -3
  69. data/lib/lerb.rb +95 -49
  70. data/lib/liza/base/box.rb +6 -1
  71. data/lib/liza/base/panel.rb +16 -18
  72. data/lib/liza/base/panel_test.rb +27 -1
  73. data/lib/liza/base_parts/controller_renderer_part.rb +1 -1
  74. data/lib/liza/ruby_tests/module_test.rb +2 -2
  75. data/lib/liza/test/test_test.rb +5 -1
  76. data/lib/liza/test_parts/test_assertions_part.rb +1 -1
  77. data/lib/liza/test_parts/test_dsl_part.rb +3 -3
  78. data/lib/liza/test_parts/test_tree_part.rb +4 -49
  79. data/lib/liza/unit.rb +73 -79
  80. data/lib/liza/unit_parts/unit_procedure_part_test.rb +9 -9
  81. data/lib/liza/unit_parts/unit_settings_part.rb +76 -0
  82. data/lib/liza/unit_parts/unit_settings_part_test.rb +3 -0
  83. data/lib/liza/unit_test.rb +11 -0
  84. data/lib/liza.rb +10 -1
  85. data/lib/lizarb/ruby/module.rb +1 -1
  86. data/lib/lizarb/version.rb +1 -1
  87. data/lib/lizarb.rb +247 -23
  88. data/lib/net_system/dev/net_command.rb +9 -9
  89. data/lib/net_system/net/controllers/client/redis_client.rb +1 -1
  90. data/lib/net_system/net/controllers/client/sqlite_client.rb +1 -1
  91. data/lib/net_system/net/net_box.rb +4 -6
  92. data/lib/web_system/dev/rack_command.rb +1 -8
  93. data/lib/web_system/dev/request_command.rb +6 -20
  94. data/lib/web_system/web/panels/request_panel.rb +0 -2
  95. data/lib/web_system/web/web_box.rb +4 -6
  96. data/lizarb.gemspec +1 -1
  97. metadata +46 -41
  98. data/.ruby-version +0 -1
  99. data/app/dev/benches/app_bench.rb +0 -5
  100. data/app/dev/benches/app_bench_test.rb +0 -7
  101. data/app/dev/benches/loops_bench_test.rb +0 -11
  102. data/app/dev/commands/app_command.rb +0 -5
  103. data/app/dev/commands/app_command_test.rb +0 -7
  104. data/app/dev/commands/new_command.rb +0 -9
  105. data/app/dev/commands/new_command_test.rb +0 -7
  106. data/app/dev/generators/bench_generator.rb +0 -18
  107. data/app/dev/generators/command_generator/command.rb.erb +0 -26
  108. data/app/dev/generators/command_generator.rb +0 -18
  109. data/exe/Gemfile.lock +0 -13
  110. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +0 -58
  111. data/lib/dev_system/dev/controllers/command/echo_command.rb +0 -9
  112. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +0 -12
  113. data/lib/dev_system/dev/controllers/command/version_command.rb +0 -7
  114. data/lib/dev_system/dev/controllers/command/version_command_test.rb +0 -12
  115. data/lib/dev_system/dev/controllers/generators/app_generator.rb +0 -146
  116. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +0 -12
  117. /data/{app → app_new}/dev/commands/calculator_command_test.rb +0 -0
  118. /data/{app → app_new}/dev/commands/circle_command_test.rb +0 -0
  119. /data/{app → app_new}/dev/commands/narrative_method_command_test.rb +0 -0
  120. /data/{app → app_new}/dev/commands/quadratic_command_test.rb +0 -0
@@ -0,0 +1,97 @@
1
+ class DevSystem::ControllerGenerator < DevSystem::Generator
2
+
3
+ def self.call args
4
+ log "args = #{args.inspect}"
5
+ new.generate_app_controller(*args)
6
+ end
7
+
8
+ def generate_app_controller system_name, controller_name, folder, name
9
+ log "(#{system_name.inspect}, #{controller_name.inspect}, #{folder.inspect}, #{name.inspect})"
10
+
11
+ @name = name
12
+ @panels = []
13
+
14
+ filename = "app/#{system_name}/#{folder}/#{name}_#{controller_name}.rb"
15
+ content = render "controller.rb"
16
+ TextShell.write filename, content
17
+
18
+ filename = "app/#{system_name}/#{folder}/#{name}_#{controller_name}_test.rb"
19
+ content = render "controller_test.rb"
20
+ TextShell.write filename, content
21
+ end
22
+
23
+ #
24
+
25
+ def self.install args
26
+ log "args = #{args.inspect}"
27
+
28
+ system_name = get(:system).name.snakecase.gsub "_system", ""
29
+ controller_name = last_namespace.snakecase.gsub "_generator", ""
30
+
31
+ new.instance_exec do
32
+ log "#install_app_panel"
33
+
34
+ @filename = "app/#{system_name}_box.rb"
35
+ @system_name = system_name
36
+ @controller_name = controller_name
37
+ @panels = {}
38
+
39
+ install_write_box unless FileShell.exist? @filename
40
+ install_read_box
41
+ install_insert_panel
42
+ install_write_box
43
+ end
44
+ end
45
+
46
+ # helper methods
47
+
48
+ def install_write_box
49
+ @content = render "app_box.rb"
50
+ TextShell.write @filename, "#{@content.strip}\n"
51
+ end
52
+
53
+ def install_read_box
54
+ @content ||= TextShell.read @filename
55
+
56
+ cursor = nil
57
+ @content.split("\n").each do |line|
58
+ md = line.match(/^ configure :(.*) do$/)
59
+ if md
60
+ cursor = md[1]
61
+ @panels[cursor] = {lines: []}
62
+ elsif line =~ /^ end$/
63
+ cursor = nil
64
+ else
65
+ next unless cursor
66
+ @panels[cursor][:lines] << line
67
+ end
68
+ end
69
+ end
70
+
71
+ def install_insert_panel
72
+ lines = render("install_insert_panel.rb").split("\n").reject(&:empty?)
73
+ @panels[@controller_name] = {lines: lines}
74
+ @panels = @panels.sort_by(&:first)
75
+ end
76
+
77
+ end
78
+
79
+ __END__
80
+
81
+ # view app_box.rb.erb
82
+
83
+ class <%= @system_name.camelcase %>Box < Liza::<%= @system_name.camelcase %>Box
84
+
85
+ <% @panels.each do |key, panel| -%>
86
+ configure :<%= key %> do
87
+ <% panel[:lines].each do |line| -%>
88
+ <%= line %>
89
+ <% end -%>
90
+ end
91
+
92
+ <% end -%>
93
+ end
94
+
95
+ # view install_insert_panel.rb.erb
96
+
97
+ #
@@ -0,0 +1,12 @@
1
+ class DevSystem::ControllerGeneratorTest < DevSystem::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::ControllerGenerator
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
@@ -4,6 +4,6 @@ end
4
4
 
5
5
  __END__
6
6
 
7
- # text.txt.erb
7
+ # view text.txt.erb
8
8
  Called <%%%= self %>.<%%%= __method__ %>
9
9
  @args: <%%%= @args %>
@@ -0,0 +1,117 @@
1
+ class DevSystem::NewGenerator < DevSystem::Generator
2
+ def self.call(args)
3
+ log "args = #{args.inspect}"
4
+ new.call args
5
+ end
6
+
7
+ def call(args)
8
+ log "args = #{args.inspect}"
9
+ # setup
10
+
11
+ name = args.shift || "app_1"
12
+
13
+ from = "#{Lizarb::APP_DIR}/app_new"
14
+ to = name
15
+
16
+ return log "Directory #{to.light_green} already exists." if Dir.exist? to
17
+
18
+ log "Liza Application initializing at `#{to}`"
19
+
20
+ # init
21
+
22
+ DirShell.create to
23
+
24
+ # app
25
+
26
+ FileUtils.cp_r from, "#{to}/app", verbose: true
27
+ FileUtils.cp_r "#{from}.rb", "#{to}/app.rb", verbose: true
28
+
29
+ # extra
30
+
31
+ puts
32
+
33
+ FileShell.gitkeep "#{to}/lib"
34
+ FileShell.gitkeep "#{to}/tmp"
35
+
36
+ TextShell.write "#{to}/.gitignore", render("hidden.gitignore")
37
+ TextShell.write "#{to}/Gemfile", render("Gemfile.rb")
38
+ # TextShell.write "#{to}/Procfile", render("Procfile.yml")
39
+ TextShell.write "#{to}/.tool-versions", render("toolversions.txt")
40
+
41
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/README.md",
42
+ "#{to}/README.md",
43
+ verbose: true
44
+ # FileUtils.cp_r "#{Lizarb::APP_DIR}/web_files",
45
+ # "#{to}/web_files",
46
+ # verbose: true
47
+ @env_name = nil
48
+ TextShell.write "#{to}/app.env", render("env.env")
49
+ @env_name = :code
50
+ TextShell.write "#{to}/app.code.env", render("env.env")
51
+ @env_name = :demo
52
+ TextShell.write "#{to}/app.demo.env", render("env.env")
53
+
54
+ puts
55
+
56
+ `cd #{to}; git init -b main; git add .; git commit -m "lizarb new app_1 (v#{Lizarb::VERSION})"`
57
+
58
+ log "Liza Application initialized at `#{to}`"
59
+ end
60
+ end
61
+
62
+ __END__
63
+
64
+ # view hidden.gitignore.erb
65
+ # Ignore all files in all subdirectories
66
+ .gitignore
67
+ /.bundle/
68
+ /tmp/
69
+ *.sqlite
70
+ *.rdb
71
+
72
+ # view toolversions.txt.erb
73
+ ruby <%= RUBY_VERSION %>
74
+
75
+ # view Procfile.yml.erb
76
+ # HEROKU EXAMPLE
77
+
78
+ web: MODE=demo bundle exec liza rack h=0.0.0.0 p=$PORT
79
+
80
+ # view Gemfile.rb.erb
81
+ # frozen_string_literal: true
82
+
83
+ source "https://rubygems.org"
84
+
85
+ group :default do
86
+ gem "lizarb", "~> <%= Lizarb::VERSION %>"
87
+ # gem "lizarb", github: "rubyonrails-brasil/lizarb"
88
+ end
89
+
90
+ group :dev do
91
+ # gems you only want to load if DevSystem is loaded
92
+ # gem "pry", "~> 0.14.1"
93
+ end
94
+
95
+ # view env.env.erb
96
+ #
97
+ <% if @env_name == :code -%>
98
+ # ENV VARIABLES FOR MODE=code (default)
99
+ #
100
+ # MODE=code lizarb commands
101
+ # lizarb commands
102
+ <% elsif @env_name == :demo -%>
103
+ # ENV VARIABLES FOR MODE=demo
104
+ #
105
+ # MODE=demo lizarb commands
106
+ <% else -%>
107
+ # ENV VARIABLES FOR ALL MODES
108
+ #
109
+ # MODE=code lizarb commands
110
+ # MODE=demo lizarb commands
111
+ # lizarb commands
112
+ <% end -%>
113
+ #
114
+
115
+ # app variables
116
+
117
+ # dev variables
@@ -0,0 +1,12 @@
1
+ class DevSystem::NewGeneratorTest < DevSystem::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::NewGenerator
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
@@ -3,25 +3,37 @@ class DevSystem::NotFoundGenerator < DevSystem::Generator
3
3
  def self.call args
4
4
  # 1. LOG
5
5
 
6
- log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+ log "args = #{args.inspect}"
7
7
  puts
8
8
 
9
9
  # 2. FIND generators
10
10
 
11
- App.eager_load_all
11
+ App.load_all
12
12
  generators = Liza::Generator.descendants
13
+ generators -= ignored_generators
13
14
 
14
- log "Liza comes with #{generators.count} generators you can use."
15
- puts
15
+ # 3. LIST generators
16
+
17
+ keys = generators.map { _1.last_namespace.snakecase[0..-11] }.uniq.sort
16
18
 
19
+ log "Liza comes with #{keys.count} generators you can use."
17
20
  log "Here they are:"
18
21
  puts
19
22
 
20
- # 3. LIST generators
23
+ keys.each do
24
+ log "liza generate #{_1}"
25
+ end
26
+ end
21
27
 
22
- keys = generators.map { |k| k.last_namespace.snakecase[0..-11] }.sort
23
- keys.reject! { |s| s == "not_found" }
24
- keys.each { |s| log "liza generate #{s}" }
28
+ def self.ignored_generators
29
+ [
30
+ self,
31
+ DevSystem::NotFoundGenerator,
32
+ DevSystem::NewGenerator,
33
+ DevSystem::ControllerGenerator,
34
+ DevSystem::RecordGenerator,
35
+ DevSystem::RequestGenerator,
36
+ ].uniq.compact
25
37
  end
26
38
 
27
39
  end
@@ -1,4 +1,4 @@
1
- class RecordGenerator < Liza::Generator
1
+ class DevSystem::RecordGenerator < DevSystem::Generator
2
2
  main_dsl
3
3
 
4
4
  FOLDER = "app/net/records"
@@ -0,0 +1,12 @@
1
+ class DevSystem::RecordGeneratorTest < DevSystem::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::RecordGenerator
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
@@ -1,4 +1,4 @@
1
- class RequestGenerator < Liza::Generator
1
+ class DevSystem::RequestGenerator < DevSystem::Generator
2
2
  main_dsl
3
3
 
4
4
  FOLDER = "app/web/requests"
@@ -23,7 +23,7 @@ class #{name.camelize}Request < Liza::Request
23
23
 
24
24
  def self.call env
25
25
  path = env["REQUEST_PATH"]
26
- log :higher, "Called \#{self}.\#{__method__} with path \#{path}"
26
+ log "args = #{args.inspect}"
27
27
 
28
28
  #
29
29
 
@@ -0,0 +1,12 @@
1
+ class DevSystem::RequestGeneratorTest < DevSystem::GeneratorTest
2
+
3
+ test :subject_class do
4
+ assert subject_class == DevSystem::RequestGenerator
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,3 @@
1
+ class DevSystem::Log < Liza::Controller
2
+
3
+ end
@@ -1,7 +1,7 @@
1
- class RequestGeneratorTest < Liza::GeneratorTest
1
+ class DevSystem::LogTest < Liza::ControllerTest
2
2
 
3
3
  test :subject_class do
4
- assert subject_class == RequestGenerator
4
+ assert subject_class == DevSystem::Log
5
5
  end
6
6
 
7
7
  test :settings do
@@ -28,4 +28,26 @@ class DevSystem::Shell < Liza::Controller
28
28
  :unix
29
29
  end
30
30
 
31
+ # Return the current Ruby engine as a symbol
32
+ def self.engine
33
+ return :jruby if jruby?
34
+ return :ruby if ruby?
35
+ :unknown
36
+ end
37
+
38
+ # Check if the current Ruby engine is JRuby
39
+ def self.jruby?
40
+ @jruby || RUBY_ENGINE == "jruby"
41
+ end
42
+
43
+ # Check if the current Ruby engine is MRI
44
+ def self.ruby?
45
+ @ruby || RUBY_ENGINE == "ruby"
46
+ end
47
+
48
+ # Return the current Ruby version as a Gem::Version
49
+ def self.ruby_version
50
+ Lizarb.ruby_version
51
+ end
52
+
31
53
  end
@@ -43,4 +43,29 @@ class DevSystem::ShellTest < Liza::ControllerTest
43
43
  subject_class.instance_variable_set(:@mac, original)
44
44
  end
45
45
 
46
+ #
47
+
48
+ test :subject_class, :ruby? do
49
+ original = subject_class.ruby?
50
+ subject_class.instance_variable_set(:@ruby, true)
51
+ assert subject_class.ruby?
52
+ ensure
53
+ subject_class.instance_variable_set(:@ruby, original)
54
+ end
55
+
56
+ test :subject_class, :jruby? do
57
+ original = subject_class.jruby?
58
+ subject_class.instance_variable_set(:@jruby, true)
59
+ assert subject_class.jruby?
60
+ ensure
61
+ subject_class.instance_variable_set(:@jruby, original)
62
+ end
63
+
64
+ #
65
+
66
+ test :subject_class, :ruby_version do
67
+ assert subject_class.ruby_version.class == Gem::Version
68
+ end
69
+
70
+
46
71
  end
@@ -1,7 +1,7 @@
1
1
  class DevSystem::IrbTerminal < DevSystem::Terminal
2
2
 
3
3
  def self.call args
4
- log :higher, "Called #{self}.#{__method__} with args #{args}"
4
+ log "args = #{args.inspect}"
5
5
 
6
6
  # https://github.com/ruby/ruby/blob/master/lib/irb.rb
7
7
  require "irb"
@@ -11,6 +11,12 @@ class DevSystem::IrbTerminal < DevSystem::Terminal
11
11
  irb = IRB::Irb.new(workspace)
12
12
  IRB.conf[:MAIN_CONTEXT] = irb.context
13
13
 
14
+ def irb.signal_status(status)
15
+ super
16
+ rescue Interrupt
17
+ IrbTerminal.log "Control-C"
18
+ end
19
+
14
20
  irb.eval_input
15
21
  end
16
22
 
@@ -1,7 +1,7 @@
1
1
  class DevSystem::PryTerminal < DevSystem::Terminal
2
2
 
3
3
  def self.call args
4
- log :higher, "Called #{self}.#{__method__} with args #{args}"
4
+ log "args = #{args.inspect}"
5
5
 
6
6
  require "pry"
7
7
  Pry.start
@@ -1,39 +1,33 @@
1
1
  class DevSystem::DevBox < Liza::Box
2
2
 
3
- # Set up your bench panel per the DSL in http://guides.lizarb.org/panels/bench.html
4
- panel :bench do
3
+ # Configure your bench panel per the DSL in http://guides.lizarb.org/panels/bench.html
4
+ configure :bench do
5
5
  # set :log_level, ENV["dev.bench.log_level"]
6
6
  end
7
7
 
8
- # Set up your command panel per the DSL in http://guides.lizarb.org/panels/command.html
9
- panel :command do
8
+ # Configure your command panel per the DSL in http://guides.lizarb.org/panels/command.html
9
+ configure :command do
10
10
  # set :log_level, ENV["dev.command.log_level"]
11
11
  end
12
12
 
13
- # Set up your generator panel per the DSL in http://guides.lizarb.org/panels/generator.html
14
- panel :generator do
13
+ # Configure your generator panel per the DSL in http://guides.lizarb.org/panels/generator.html
14
+ configure :generator do
15
15
  # set :log_level, ENV["dev.generator.log_level"]
16
16
  end
17
17
 
18
- # Set up your command panel per the DSL in http://guides.lizarb.org/panels/log.html
19
- panel :log do
18
+ # Configure your command panel per the DSL in http://guides.lizarb.org/panels/log.html
19
+ configure :log do
20
20
  # set :log_level, ENV["dev.log.log_level"]
21
21
  end
22
22
 
23
- # Set up your shell panel per the DSL in http://guides.lizarb.org/panels/shell.html
24
- panel :shell do
23
+ # Configure your shell panel per the DSL in http://guides.lizarb.org/panels/shell.html
24
+ configure :shell do
25
25
  # set :log_level, ENV["dev.shell.log_level"]
26
26
  end
27
27
 
28
- # Set up your terminal panel per the DSL in http://guides.lizarb.org/panels/terminal.html
29
- panel :terminal do
28
+ # Configure your terminal panel per the DSL in http://guides.lizarb.org/panels/terminal.html
29
+ configure :terminal do
30
30
  # set :log_level, ENV["dev.terminal.log_level"]
31
31
  end
32
32
 
33
- has_controller :bench, :bench
34
- has_controller :command, :command
35
- has_controller :generator, :generator
36
- # has_controller :log, :log
37
- has_controller :shell, :shell
38
- has_controller :terminal, :terminal
39
33
  end
@@ -1,28 +1,71 @@
1
1
  class DevSystem::CommandPanel < Liza::Panel
2
+ class Error < StandardError; end
3
+ class ParseError < Error; end
2
4
 
3
5
  def call args
4
- # 1. LOG
6
+ log "args = #{args.inspect}" if get :log_details
5
7
 
6
- log "call #{args}"
8
+ return call_not_found args if args.none?
7
9
 
8
- # 2. FIND command
10
+ struct = parse args[0]
11
+ struct.command = short struct.command
12
+ command = find struct.command
9
13
 
10
- return call_not_found args if args.none?
14
+ case
15
+ when struct.class_method
16
+ _call_log "#{command}.#{struct.class_method}(#{args[1..-1]})"
17
+ command.public_send struct.class_method, args[1..-1]
18
+ when struct.instance_method
19
+ _call_log "#{command}.new.#{struct.instance_method}(#{args[1..-1]})"
20
+ command.new.public_send struct.instance_method, args[1..-1]
21
+ when struct.method
22
+ if command.respond_to?(struct.method)
23
+ _call_log "#{command}.#{struct.method}(#{args[1..-1]})"
24
+ command.public_send struct.method, args[1..-1]
25
+ else
26
+ _call_log "#{command}.new.#{struct.method}(#{args[1..-1]})"
27
+ command.new.public_send struct.method, args[1..-1]
28
+ end
29
+ else
30
+ _call_log "#{command}.call(#{args[1..-1]})"
31
+ command.call args[1..-1]
32
+ end
33
+ rescue ParseError
34
+ call_not_found args
35
+ end
36
+
37
+ def _call_log string
38
+ log "#{string}" if get :log_details
39
+ end
11
40
 
12
- command = args[0]
41
+ #
13
42
 
14
- log({command:})
43
+ PARSE_REGEX = /(?<command>[A-Za-z_]+)(?::(?<class_method>[a-z_]+))?(?:#(?<instance_method>[a-z_]+))?(?:\.(?<method>[a-z_]+))?/
15
44
 
16
- command_klass = Liza.const "#{command}_command"
45
+ # OpenStruct command class_method instance_method method
46
+ def parse string
47
+ md = string.to_s.match PARSE_REGEX
48
+ raise ParseError if md.nil?
49
+ hash = md.named_captures
50
+ log "{#{hash.map { ":#{_1}=>#{_2.to_s.inspect}" }.join(", ") }}" if get :log_details
51
+ OpenStruct.new hash
52
+ end
17
53
 
18
- # 3. CALL
54
+ #
19
55
 
20
- command_klass.call args[1..-1]
56
+ def find string
57
+ k = Liza.const "#{string}_command"
21
58
  rescue Liza::ConstNotFound
22
- call_not_found args
59
+ k = Liza::NotFoundCommand
60
+ ensure
61
+ log k.to_s if get :log_details
62
+ k
23
63
  end
24
64
 
65
+ #
66
+
25
67
  def call_not_found args
26
- Liza::NotFoundCommand.call args
68
+ Liza[:NotFoundCommand].call args
27
69
  end
70
+
28
71
  end
@@ -1,21 +1,46 @@
1
1
  class DevSystem::CommandPanelTest < Liza::PanelTest
2
2
 
3
3
  test :subject_class do
4
- assert subject_class == DevSystem::CommandPanel
4
+ assert_equality subject_class, DevSystem::CommandPanel
5
5
  end
6
6
 
7
7
  test :settings do
8
- assert subject_class.log_level == :normal
9
- assert subject_class.log_color == :green
8
+ assert_equality subject_class.log_level, :normal
9
+ assert_equality subject_class.log_color, :green
10
10
  end
11
11
 
12
- test :call do
13
- begin
14
- subject.call ["echo", 1, 2, 3]
15
- assert false
16
- rescue RuntimeError => e
17
- assert e.message == "[1, 2, 3]"
18
- end
12
+ test :parse do
13
+ struct = subject.parse "generate"
14
+ assert_equality struct.command, "generate"
15
+ assert_equality struct.class_method, nil
16
+ assert_equality struct.instance_method, nil
17
+ assert_equality struct.method, nil
18
+
19
+ struct = subject.parse "generate:install"
20
+ assert_equality struct.command, "generate"
21
+ assert_equality struct.class_method, "install"
22
+ assert_equality struct.instance_method, nil
23
+ assert_equality struct.method, nil
24
+
25
+ struct = subject.parse "generate#install"
26
+ assert_equality struct.command, "generate"
27
+ assert_equality struct.class_method, nil
28
+ assert_equality struct.instance_method, "install"
29
+ assert_equality struct.method, nil
30
+
31
+ struct = subject.parse "generate.install"
32
+ assert_equality struct.command, "generate"
33
+ assert_equality struct.class_method, nil
34
+ assert_equality struct.instance_method, nil
35
+ assert_equality struct.method, "install"
36
+ end
37
+
38
+ test :find do
39
+ klass = subject.find "generate"
40
+ assert_equality DevSystem::GenerateCommand, klass
41
+
42
+ klass = subject.find "g"
43
+ assert_equality DevSystem::NotFoundCommand, klass
19
44
  end
20
45
 
21
46
  end