lizarb 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +10 -2
  4. data/README.md +2 -2
  5. data/app/dev/benches/app_bench.rb +5 -0
  6. data/app/dev/benches/app_bench_test.rb +7 -0
  7. data/app/dev/benches/loops_bench.rb +148 -0
  8. data/app/dev/benches/loops_bench_test.rb +11 -0
  9. data/app/dev/commands/new_command.rb +1 -61
  10. data/app/dev/generators/bench_generator.rb +67 -0
  11. data/app/dev/generators/bench_generator_test.rb +12 -0
  12. data/app/dev/generators/command_generator.rb +51 -0
  13. data/app/dev/generators/command_generator_test.rb +12 -0
  14. data/app/dev/generators/model_generator.rb +46 -0
  15. data/app/dev/generators/model_generator_test.rb +12 -0
  16. data/app/dev/generators/request_generator.rb +63 -0
  17. data/app/dev/generators/request_generator_test.rb +12 -0
  18. data/app/net/databases/redis_db_test.rb +2 -2
  19. data/app/net/databases/sqlite_db_test.rb +2 -2
  20. data/app/net_box.rb +2 -2
  21. data/lib/app.rb +1 -1
  22. data/lib/dev_system/dev/controllers/bench.rb +11 -0
  23. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
  24. data/lib/dev_system/dev/controllers/bench_test.rb +14 -0
  25. data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
  26. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
  27. data/lib/dev_system/dev/controllers/command/dev_command.rb +13 -8
  28. data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
  29. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
  30. data/lib/dev_system/dev/controllers/generator.rb +11 -0
  31. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
  32. data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
  33. data/lib/dev_system/dev/controllers/generators/app_generator.rb +71 -0
  34. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
  35. data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
  36. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
  37. data/lib/dev_system/dev/controllers/shell.rb +19 -0
  38. data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
  39. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
  40. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
  41. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
  42. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
  43. data/lib/dev_system/dev/controllers/terminal.rb +19 -0
  44. data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
  45. data/lib/dev_system/dev/dev_box.rb +3 -0
  46. data/lib/liza/test_parts/test_subject_part.rb +6 -1
  47. data/lib/liza.rb +35 -7
  48. data/lib/lizarb/ruby/class.rb +2 -0
  49. data/lib/lizarb/ruby/proc.rb +12 -0
  50. data/lib/lizarb/ruby/string.rb +16 -0
  51. data/lib/lizarb/version.rb +1 -1
  52. data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
  53. data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
  54. data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
  55. data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
  56. data/lib/net_system/net/controllers/client.rb +5 -0
  57. data/lib/net_system/net/controllers/{adapter_test.rb → client_test.rb} +2 -2
  58. data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
  59. data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
  60. data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
  61. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
  62. data/lib/net_system/net/controllers/database.rb +6 -6
  63. data/lib/net_system/net/net_box.rb +5 -5
  64. data/lib/net_system/net/net_box_test.rb +1 -1
  65. data/lib/net_system/net/panels/client_panel.rb +5 -0
  66. data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
  67. data/tmp/.gitkeep +0 -0
  68. metadata +46 -10
  69. data/lib/net_system/net/controllers/adapter.rb +0 -5
  70. data/lib/net_system/net/panels/adapter_panel.rb +0 -5
@@ -0,0 +1,60 @@
1
+ class DevSystem
2
+ class BenchDslMainPart < Liza::Part
3
+
4
+ insertion do
5
+
6
+ def self.call args
7
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
8
+
9
+ # https://rubyapi.org/3.1/o/benchmark
10
+ require "benchmark"
11
+
12
+ if @setup_bl
13
+ log "Setting up..."
14
+ instance_exec &@setup_bl
15
+ log "Set up"
16
+ end
17
+
18
+ log "Benchmarking #{marks.count} Ruby Blocks"
19
+ puts
20
+
21
+ length = marks.keys.map(&:length).max
22
+
23
+ marks.each do |label, bl|
24
+ log "Benchmarking #{label}"
25
+ marks[label] = Benchmark.measure label, &bl
26
+ end
27
+
28
+ puts
29
+
30
+ log "#{"Reporting".ljust_blanks(length + 17)} App CPU Time Kernel CPU Time Total CPU Time"
31
+ puts
32
+
33
+ sorted = marks.sort_by { |_k, tms| tms.total }.to_h
34
+
35
+ sorted.each.with_index do |(label, tms), i|
36
+ tms = tms.format "%10.6u %10.6y %10.6t"
37
+ s = "[#{i.next.to_s.rjust_zeroes 2}/#{marks.count.to_s.rjust_zeroes 2}] #{label.rjust_blanks length} #{tms}"
38
+
39
+ s = s.green if i == 0
40
+ s = s.red if i == marks.count-1
41
+ log s
42
+ end
43
+ puts
44
+ log "Done"
45
+ end
46
+
47
+ #
48
+
49
+ def self.marks()= @marks ||= {}
50
+
51
+ def self.mark(label, &block)= marks[label] = block
52
+
53
+ def self.setup &block
54
+ @setup_bl = block if block_given?
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class BenchTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::Bench
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,24 @@
1
+ class DevSystem
2
+ class BenchCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "args: #{args}"
8
+ puts
9
+
10
+ # 2. FIND bench
11
+
12
+ bench = args[0]
13
+
14
+ log({bench:})
15
+
16
+ bench_klass = Liza.const "#{bench}_bench"
17
+
18
+ # 3. CALL
19
+
20
+ bench_klass.call args[1..-1]
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class BenchCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::BenchCommand
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
@@ -2,17 +2,22 @@ class DevSystem
2
2
  class DevCommand < Command
3
3
 
4
4
  def self.call args
5
- log :higher, "Called #{self} with args #{args}"
5
+ # 1. LOG
6
6
 
7
- # https://github.com/ruby/ruby/blob/master/lib/irb.rb
8
- require "irb"
7
+ log :higher, "args: #{args}"
8
+ puts
9
9
 
10
- IRB.setup(nil)
11
- workspace = IRB::WorkSpace.new(binding)
12
- irb = IRB::Irb.new(workspace)
13
- IRB.conf[:MAIN_CONTEXT] = irb.context
10
+ # 2. FIND terminal
14
11
 
15
- irb.eval_input
12
+ terminal = args[0] || "irb"
13
+
14
+ log({terminal:})
15
+
16
+ terminal_klass = Liza.const "#{terminal}_terminal"
17
+
18
+ # 3. CALL
19
+
20
+ terminal_klass.call Array(args[1..-1])
16
21
  end
17
22
 
18
23
  end
@@ -0,0 +1,23 @@
1
+ class DevSystem
2
+ class GenerateCommand < Command
3
+
4
+ def self.call args
5
+ # 1. LOG
6
+
7
+ log :higher, "args: #{args}"
8
+ puts
9
+
10
+ # 2. FIND generator
11
+
12
+ generator = args[0]
13
+
14
+ log({generator:})
15
+
16
+ generator_klass = Liza.const "#{generator}_generator"
17
+
18
+ # 3. CALL
19
+
20
+ generator_klass.call args[1..-1]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class GenerateCommandTest < CommandTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::GenerateCommand
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,11 @@
1
+ class DevSystem
2
+ class Generator < Liza::Controller
3
+
4
+ # DSLS
5
+
6
+ def self.main_dsl
7
+ part :"generator_dsl_main", system: :dev
8
+ end
9
+
10
+ end
11
+ end
@@ -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
+ FileShell.write folder, filename, content
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,71 @@
1
+ class DevSystem
2
+ class AppGenerator < Generator
3
+
4
+ def self.call args
5
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+
7
+ # setup
8
+
9
+ name = args.shift || "app_1"
10
+
11
+ from = "#{Lizarb::APP_DIR}/app_new"
12
+ to = name
13
+
14
+ return log "Directory #{to.light_green} already exists." if Dir.exist? to
15
+
16
+ log "Liza Application initializing at `#{to}`"
17
+
18
+ # init
19
+
20
+ require "fileutils"
21
+ FileUtils.cp_r from, to, verbose: true
22
+
23
+ `cd #{to}; git init .`
24
+
25
+ # extra
26
+
27
+ puts
28
+
29
+ FileShell.gitkeep "#{to}/lib"
30
+ FileShell.gitkeep "#{to}/tmp"
31
+
32
+ FileShell.create_folder "#{to}/app"
33
+
34
+ # systems
35
+
36
+ App.systems.keys.each { |system_name| copy to, system_name }
37
+
38
+ FileUtils.rm "#{to}/app/dev/commands/new_command.rb"
39
+ FileUtils.rm "#{to}/app/dev/commands/new_command_test.rb"
40
+
41
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/.ruby-version", "#{to}/.ruby-version", verbose: true
42
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/README.md", "#{to}/README.md", verbose: true
43
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/app.rb", "#{to}/app.rb", verbose: true
44
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/app.env", "#{to}/app.env", verbose: true
45
+ FileUtils.cp_r "#{Lizarb::APP_DIR}/app.code.env", "#{to}/app.code.env", verbose: true
46
+
47
+ puts
48
+
49
+ log "Liza Application initialized at `#{to}`"
50
+ end
51
+
52
+ def self.copy name, system_name
53
+ from = "#{Lizarb::APP_DIR}/app/#{system_name}_box.rb"
54
+ to = "#{name}/app"
55
+ if File.exist? from
56
+ FileUtils.cp_r from, to, verbose: true
57
+ else
58
+ puts "file not found #{from}"
59
+ end
60
+
61
+ from = "#{Lizarb::APP_DIR}/app/#{system_name}"
62
+ to = "#{name}/app"
63
+ if File.exist? from
64
+ FileUtils.cp_r from, to, verbose: true
65
+ else
66
+ puts "file not found #{from}"
67
+ end
68
+ end
69
+
70
+ end
71
+ 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,29 @@
1
+ class DevSystem
2
+ class FileShell < Shell
3
+ require "fileutils"
4
+
5
+ def self.create_folder folder, write_log = true
6
+ log "Creating folder #{folder}" if write_log
7
+ FileUtils.mkdir_p folder
8
+ end
9
+
10
+ def self.write folder, filename, content
11
+ create_folder folder, false
12
+ fname = "#{folder}/#{filename}"
13
+ log "Writing #{fname} with #{content.size} bytes"
14
+ File.write fname, content
15
+ end
16
+
17
+ def self.touch folder, filename
18
+ create_folder folder, false
19
+ fname = "#{folder}/#{filename}"
20
+ log "Touching #{fname}"
21
+ FileUtils.touch fname
22
+ end
23
+
24
+ def self.gitkeep folder
25
+ touch folder, ".gitkeep"
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class FileShellTest < ShellTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::FileShell
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,19 @@
1
+ class DevSystem
2
+ class Shell < Liza::Controller
3
+ def windows?
4
+ RUBY_PLATFORM =~ /win32/
5
+ end
6
+
7
+ def unix?
8
+ linux? || mac?
9
+ end
10
+
11
+ def linux?
12
+ RUBY_PLATFORM =~ /linux/
13
+ end
14
+
15
+ def mac?
16
+ RUBY_PLATFORM =~ /darwin/
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ class DevSystem
2
+ class ShellTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::Shell
6
+ end
7
+
8
+ test :settings do
9
+ assert subject_class.log_level == :normal
10
+ assert subject_class.log_color == :green
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ class DevSystem
2
+ class IrbTerminal < Terminal
3
+
4
+ def self.call args
5
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+
7
+ # https://github.com/ruby/ruby/blob/master/lib/irb.rb
8
+ require "irb"
9
+
10
+ IRB.setup(nil)
11
+ workspace = IRB::WorkSpace.new(binding)
12
+ irb = IRB::Irb.new(workspace)
13
+ IRB.conf[:MAIN_CONTEXT] = irb.context
14
+
15
+ irb.eval_input
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class IrbTerminalTest < TerminalTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::IrbTerminal
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,12 @@
1
+ class DevSystem
2
+ class PryTerminal < Terminal
3
+
4
+ def self.call args
5
+ log :higher, "Called #{self}.#{__method__} with args #{args}"
6
+
7
+ require "pry"
8
+ Pry.start
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class PryTerminalTest < TerminalTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::PryTerminal
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,19 @@
1
+ class DevSystem
2
+ class Terminal < Liza::Controller
3
+
4
+ # def self.call args
5
+ # new.call args
6
+ # end
7
+
8
+ # def initialize args
9
+ # @args = args
10
+ # end
11
+
12
+ # attr_reader :args
13
+
14
+ # def call args
15
+ #
16
+ # end
17
+
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class DevSystem
2
+ class TerminalTest < Liza::ControllerTest
3
+
4
+ test :subject_class do
5
+ assert subject_class == DevSystem::Terminal
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
@@ -2,6 +2,9 @@ class DevSystem
2
2
  class DevBox < Liza::Box
3
3
  has_panel :command, :commands
4
4
  has_controller :command, :commands
5
+ has_controller :shell, :commands
6
+ has_controller :bench, :commands
7
+ has_controller :terminal, :commands
5
8
 
6
9
  has_panel :log, :logs
7
10
 
@@ -3,7 +3,12 @@ module Liza
3
3
 
4
4
  insertion do
5
5
  def self.subject_class
6
- @subject_class ||= Liza::const name[0..-5]
6
+ @subject_class ||=
7
+ if first_namespace == "Liza"
8
+ Liza.const_get last_namespace[0..-5]
9
+ else
10
+ Object.const_get name[0..-5]
11
+ end
7
12
  end
8
13
 
9
14
  def subject_class
data/lib/liza.rb CHANGED
@@ -13,22 +13,50 @@ module Liza
13
13
 
14
14
  #
15
15
 
16
- # After checking the top-level namespace, looks up the Liza namespace
16
+ # Checks Object, each system, then Liza for Liza::Unit classes
17
17
  def const name
18
- name = name.to_s.camelize
18
+ name = name.to_s.camelize.to_sym
19
19
 
20
- return Object.const_get name if Object.const_defined? name
20
+ k = const_check_object name
21
+ return k if k
21
22
 
22
- const_get name
23
+ k = const_check_systems name
24
+ return k if k
25
+
26
+ k = const_get name
27
+ return k if k
28
+
29
+ nil
23
30
  end
24
31
 
25
- # constants missing from Liza will be looked up in all systems
32
+ # Checks each system, then Liza for Liza::Unit classes
26
33
  def const_missing name
34
+ k = const_check_systems name
35
+ return k if k
36
+
37
+ super
38
+ end
39
+
40
+ def const_check_object name
41
+ return if not Object.const_defined? name
42
+ kk = Object.const_get name
43
+ return kk if is_unit? kk
44
+
45
+ nil
46
+ end
47
+
48
+ def const_check_systems name
27
49
  for k in App.systems.values.reverse
28
- return k.const_get(name) if k.const_defined? name
50
+ next if not k.const_defined? name.to_sym
51
+ kk = k.const(name) if k.constants.include? name
52
+ return kk if is_unit? kk
29
53
  end
30
54
 
31
- super
55
+ nil
56
+ end
57
+
58
+ def is_unit? kk
59
+ kk && kk < Liza::Unit
32
60
  end
33
61
 
34
62
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Class
4
+ public :eval
5
+
4
6
  def descendants
5
7
  ObjectSpace.each_object(Class).select { |klass| klass < self }
6
8
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Proc
4
+ def relative_source
5
+ absolute_source.gsub "#{Lizarb::APP_DIR}/", ""
6
+ end
7
+
8
+ def absolute_source
9
+ sl = source_location
10
+ "#{sl[0]}:#{sl[1]}"
11
+ end
12
+ end
@@ -6,4 +6,20 @@ class String
6
6
  def camelize
7
7
  split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
8
8
  end
9
+
10
+ def rjust_blanks length
11
+ rjust length, " "
12
+ end
13
+
14
+ def rjust_zeroes length
15
+ rjust length, "0"
16
+ end
17
+
18
+ def ljust_blanks length
19
+ ljust length, " "
20
+ end
21
+
22
+ def ljust_zeroes length
23
+ ljust length, "0"
24
+ end
9
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lizarb
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.1"
5
5
  end