lizarb 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.tool-versions +1 -0
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +7 -4
  6. data/README.md +23 -64
  7. data/README_SYSTEMS.md +80 -0
  8. data/Rakefile +3 -1
  9. data/app/dev/benches/loops_bench.rb +35 -0
  10. data/app/dev/commands/calculator_command.rb +69 -0
  11. data/app/dev/commands/calculator_command_test.rb +58 -0
  12. data/app/dev/commands/circle_command.rb +70 -0
  13. data/app/dev/commands/circle_command_test.rb +76 -0
  14. data/app/dev/commands/narrative_method_command.rb +60 -0
  15. data/app/dev/commands/narrative_method_command_test.rb +36 -0
  16. data/app/dev/commands/quadratic_command.rb +66 -0
  17. data/app/dev/commands/quadratic_command_test.rb +47 -0
  18. data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
  19. data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
  20. data/app/dev/generators/bench_generator.rb +2 -51
  21. data/app/dev/generators/command_generator/command.rb.erb +26 -0
  22. data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
  23. data/app/dev/generators/command_generator.rb +2 -35
  24. data/app/dev/generators/record_generator.rb +46 -0
  25. data/app/dev/generators/{model_generator_test.rb → record_generator_test.rb} +2 -2
  26. data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
  27. data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
  28. data/app/net/records/post_record.rb +4 -0
  29. data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
  30. data/app/net/records/user_record.rb +4 -0
  31. data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
  32. data/app/web/requests/api_request.rb +8 -7
  33. data/app/web/requests/assets_request.rb +12 -13
  34. data/app/web/requests/root_request.rb +6 -7
  35. data/app/web/requests/root_request_test.rb +1 -1
  36. data/app/web_box.rb +8 -0
  37. data/app_new/Procfile +1 -1
  38. data/exe/lrb +3 -0
  39. data/lib/app.rb +18 -14
  40. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
  41. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
  42. data/lib/dev_system/dev/controllers/command/bench_command.rb +11 -1
  43. data/lib/dev_system/dev/controllers/command/generate_command.rb +14 -2
  44. data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
  45. data/lib/dev_system/dev/controllers/command/{dev_command_test.rb → not_found_command_test.rb} +2 -2
  46. data/lib/dev_system/dev/controllers/command/{dev_command.rb → terminal_command.rb} +1 -1
  47. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
  48. data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
  49. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +1 -1
  50. data/lib/dev_system/dev/controllers/generators/app_generator.rb +30 -5
  51. data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
  52. data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
  53. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
  54. data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
  55. data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
  56. data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
  58. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
  59. data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
  60. data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
  61. data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
  62. data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
  63. data/lib/dev_system/dev/controllers/shell/file_shell.rb +56 -26
  64. data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +143 -7
  65. data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
  66. data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
  67. data/lib/dev_system/dev/controllers/shell.rb +26 -14
  68. data/lib/dev_system/dev/controllers/shell_test.rb +42 -9
  69. data/lib/dev_system/dev/panels/command_panel.rb +21 -1
  70. data/lib/dev_system/dev/panels/log_panel.rb +1 -1
  71. data/lib/lerb.rb +106 -0
  72. data/lib/liza/base/controller.rb +2 -0
  73. data/lib/liza/base/panel.rb +6 -5
  74. data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
  75. data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
  76. data/lib/liza/meta/part_extension.rb +6 -1
  77. data/lib/liza/ruby_test.rb +9 -0
  78. data/lib/liza/ruby_tests/module_test.rb +21 -0
  79. data/lib/liza/ruby_tests/string_test.rb +59 -0
  80. data/lib/liza/test/test.rb +3 -1
  81. data/lib/liza/test/test_test.rb +108 -15
  82. data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
  83. data/lib/liza/test_parts/test_assertions_part.rb +7 -6
  84. data/lib/liza/test_parts/test_dsl_part.rb +37 -89
  85. data/lib/liza/test_parts/test_log_part.rb +124 -0
  86. data/lib/liza/test_parts/test_tree_part.rb +139 -0
  87. data/lib/liza/unit.rb +2 -0
  88. data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
  89. data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
  90. data/lib/liza.rb +5 -0
  91. data/lib/lizarb/ruby/module.rb +17 -0
  92. data/lib/lizarb/ruby/string.rb +10 -2
  93. data/lib/lizarb/version.rb +1 -1
  94. data/lib/lizarb.rb +24 -2
  95. data/lib/net_system/net/controllers/record.rb +31 -0
  96. data/lib/net_system/net/controllers/{model_test.rb → record_test.rb} +2 -2
  97. data/lib/web_system/dev/rack_command.rb +26 -0
  98. data/lib/web_system/dev/request_command.rb +143 -0
  99. data/lib/web_system/dev/web_command.rb +3 -34
  100. data/lib/web_system/web/controllers/rack.rb +8 -0
  101. data/lib/web_system/web/controllers/rack_test.rb +18 -0
  102. data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
  103. data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
  104. data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
  105. data/lib/web_system/web/panels/rack_panel.rb +44 -0
  106. data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
  107. data/lib/web_system/web/panels/request_panel.rb +51 -32
  108. data/lib/web_system/web/panels/request_panel_test.rb +28 -9
  109. data/lib/web_system/web/web_box.rb +12 -0
  110. data/lizarb.gemspec +2 -2
  111. metadata +68 -25
  112. data/app/dev/commands/example_command.rb +0 -57
  113. data/app/dev/commands/example_command_test.rb +0 -43
  114. data/app/dev/commands/macro_child_command.rb +0 -32
  115. data/app/dev/commands/macro_child_command_test.rb +0 -7
  116. data/app/dev/commands/macro_parent_command.rb +0 -70
  117. data/app/dev/commands/macro_parent_command_test.rb +0 -7
  118. data/app/dev/commands/my_command.rb +0 -7
  119. data/app/dev/commands/my_command_test.rb +0 -7
  120. data/app/dev/generators/model_generator.rb +0 -46
  121. data/app/net/models/post_model.rb +0 -4
  122. data/app/net/models/user_model.rb +0 -4
  123. data/lib/liza/test_parts/test_context_part.rb +0 -81
  124. data/lib/net_system/net/controllers/model.rb +0 -31
@@ -1,122 +1,70 @@
1
1
  module Liza
2
2
  class TestDslPart < Part
3
3
  insertion do
4
- def self.test *words, &block
5
- Liza.log "#{inspect}.test #{words}, &block"
6
- block_given? || raise(ArgumentError, "No block given")
7
-
8
- key = [
9
- block.source_location,
10
- 'b',
11
- context.befores.flatten.map(&:source_location),
12
- 'a',
13
- context.afters.flatten.map(&:source_location),
14
- ].flatten.join("-")
15
-
16
- key.gsub! Lizarb::CUR_DIR, ""
17
-
18
- instances[key] ||= new words,
19
- context.befores.flatten.uniq,
20
- context.afters.flatten.uniq,
21
- &block
22
- end
23
-
24
- def self.instances
25
- @instances ||= {}
26
- end
27
4
 
28
5
  def self.call class_index, class_count
29
6
  counter_class = "#{class_index.to_s.rjust 3, "0"}/#{class_count.to_s.rjust 3, "0"}"
30
7
 
31
- puts "- #{counter_class} #{self} (#{instances.size} tests)".cyan
8
+ log "+ #{counter_class} #{self} class".bold.white
9
+
10
+ array = [test_tree]
11
+ while array.any?
12
+ node = array.pop
13
+ i = 0
32
14
 
33
- instances.values.each_with_index do |instance, i|
34
- counter_instance = "#{(i+=1).to_s.rjust 2, '0'}/#{instances.size.to_s.rjust 2, '0'}"
35
- label = instance.words_as_label
15
+ node.tests.each do |test_words, test_block|
16
+ counter_instance = "#{(i+=1).to_s.rjust 2, '0'}/#{node.tests.size.to_s.rjust 2, '0'}"
17
+ label = test_words.to_a.flatten.join(" ")[0..25]
36
18
 
37
- puts " #{ counter_class } #{ counter_instance } (#{ label })".light_cyan
19
+ log " #{ counter_class } #{ counter_instance } #{ label.ljust(27)} #{_log_test_block test_block}"
38
20
 
39
- instance.call
21
+ log_test_building node, test_block if log_test_building?
22
+
23
+ instance = new test_words, node.before_stack, node.after_stack, &test_block
24
+ instance.call
25
+ end
26
+
27
+ array.concat node.children
40
28
  end
41
- end
42
29
 
43
- #
30
+ end
44
31
 
45
- attr_reader :words
32
+ attr_reader :test_words
46
33
 
47
- def initialize words, befores, afters, &block
48
- @words, @befores, @afters, @block = words, befores, afters, block
34
+ def initialize test_words, before_stack, after_stack, &test_block
35
+ @test_words, @before_stack, @after_stack, @test_block = test_words, before_stack, after_stack, test_block
49
36
  end
50
37
 
51
38
  def call
52
39
  catch :critical do
53
- @befores.each do |bl|
54
- _call_log "B&", &bl
55
- instance_exec &bl
40
+ @before_stack.each do |stack|
41
+ log " calling stacked before blocks #{stack.map { |bl| _log_test_block bl }}".magenta if log_test_building?
42
+ stack.each do |bl|
43
+ log_test_call "B&", &bl if log_test_call_block?
44
+ instance_exec &bl
45
+ end
56
46
  end
57
47
 
58
- bl = @block
59
- _call_log " &", &bl
48
+ bl = @test_block
49
+ log " calling test block #{_log_test_block bl}".magenta if log_test_building?
50
+ log_test_call "T&", &bl if log_test_call_block?
60
51
  instance_exec &bl
61
52
 
62
- @afters.each do |bl|
63
- _call_log "A&", &bl
64
- instance_exec &bl
53
+ @after_stack.each do |stack|
54
+ log " calling stacked after blocks #{stack.map { |bl| _log_test_block bl }}".magenta if log_test_building?
55
+ stack.each do |bl|
56
+ log_test_call "A&", &bl if log_test_call_block?
57
+ instance_exec &bl
58
+ end
65
59
  end
66
60
  end
67
61
  rescue Exception => e
68
62
  self.class._assertion_errored e
69
- _rescue_log e
63
+ log_test_call_rescue e
70
64
  ensure
71
65
  puts
72
66
  end
73
67
 
74
- def words_as_label
75
- label = words.to_s
76
- label = label[1..-2] if label.start_with? "["
77
- label = label[1..-2] if label.start_with? "{"
78
- label
79
- end
80
-
81
- def _rescue_log e
82
- prefix = "error"
83
-
84
- kaller = e.backtrace
85
-
86
- source_location = _caller_line_split(kaller[0])[0]
87
- source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
88
-
89
- log " #{prefix} #{source_location}"
90
-
91
- puts "Exception!".red
92
- puts e.class.to_s.red
93
- puts e.message.red
94
- puts
95
- puts e.backtrace.join("\n").red
96
- end
97
-
98
- def _call_log prefix, &block
99
- source_location = block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
100
- source_location = source_location[0..-1]
101
- log " #{prefix} #{source_location}"
102
- end
103
-
104
- def _assertion_log method_name, kaller
105
- _inc_assertions
106
- method_name = method_name.to_s.ljust 6
107
- prefix = "#{assertions} #{method_name} #{@last_result}"
108
-
109
- source_location = _caller_line_split(kaller[0])[0]
110
- source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
111
-
112
- log " #{prefix} #{source_location}"
113
- end
114
-
115
- def _caller_line_split s
116
- x = s.split ":in `"
117
- x[1] = x[1][0..-2]
118
- x
119
- end
120
68
  end
121
69
  end
122
70
  end
@@ -0,0 +1,124 @@
1
+ module Liza
2
+ class TestLogPart < Part
3
+
4
+ insertion do
5
+
6
+ LOG_BUILDING = false
7
+ LOG_ASSERTION = true
8
+ LOG_ASSERTION_MESSAGE = true
9
+ LOG_CALL_BLOCK = true
10
+
11
+ def self.log_test_building?
12
+ LOG_BUILDING
13
+ end
14
+
15
+ def log_test_building?
16
+ self.class.log_test_building?
17
+ end
18
+
19
+ def log_test_assertion?
20
+ LOG_ASSERTION
21
+ end
22
+
23
+ def log_test_assertion_message?
24
+ LOG_ASSERTION_MESSAGE
25
+ end
26
+
27
+ def log_test_call_block?
28
+ LOG_CALL_BLOCK
29
+ end
30
+
31
+ def log_test_call_rescue e
32
+ prefix = "error".yellow
33
+
34
+ kaller = e.backtrace
35
+
36
+ source_location = _caller_line_split(kaller[0])[0]
37
+ source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
38
+
39
+ log " #{prefix} #{e.class.to_s.ljust 20} #{source_location}"
40
+
41
+ puts "Exception!".red
42
+ puts e.class.to_s.red
43
+ puts e.message.red
44
+ puts
45
+ puts e.backtrace.join("\n").red
46
+ end
47
+
48
+ def self.log_test_building node, test_block
49
+ log " the building blocks are".magenta
50
+
51
+ node.before_stack.each do |stack|
52
+ stack.each do |bl|
53
+ log " before block #{_log_test_block bl}".magenta
54
+ end
55
+ end
56
+
57
+ log " test block #{_log_test_block test_block}".magenta
58
+
59
+ node.after_stack.each do |stack|
60
+ stack.each do |bl|
61
+ log " after block #{_log_test_block bl}".magenta
62
+ end
63
+ end
64
+ end
65
+
66
+ def log_test_call prefix, &block
67
+ source_location = block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
68
+ source_location = source_location[0..-1]
69
+ log " #{prefix} #{source_location}"
70
+ end
71
+
72
+ def log_test_assertion method_name, kaller
73
+ _inc_assertions
74
+ prefix = "#{assertions.to_s.rjust 2, "0"} #{_log_test_assertion_tag method_name}"
75
+
76
+ source_location = _caller_line_split(kaller[0])[0]
77
+ source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
78
+
79
+ log " #{prefix} #{source_location}" if log_test_assertion?
80
+ end
81
+
82
+ def _log_test_assertion_tag method_name
83
+ "#{log_test_assertion_result} #{method_name.to_s.ljust(20).bold.white}"
84
+ end
85
+
86
+ def self._log_test_block test_block
87
+ test_block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
88
+ end
89
+
90
+ def _log_test_block test_block
91
+ self.class._log_test_block test_block
92
+ end
93
+
94
+ def log_test_assertion_result
95
+ case @last_result
96
+ when :todo
97
+ " todo".blue
98
+ when :passed
99
+ "passed".green
100
+ when :failed
101
+ "failed".red
102
+ else
103
+ raise "Unknown result: #{@last_result}"
104
+ end
105
+ end
106
+
107
+ def log_test_assertion_message b, msg
108
+ if b
109
+ log " passed #{msg}".green
110
+ else
111
+ log " failed #{msg}".red
112
+ end
113
+ end
114
+
115
+ def _caller_line_split s
116
+ x = s.split ":in `"
117
+ x[1] = x[1][0..-2]
118
+ x
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,139 @@
1
+ module Liza
2
+ class TestTreePart < Part
3
+
4
+ insertion do
5
+
6
+ @before_stack = []
7
+ @after_stack = []
8
+
9
+ def self.before_stack; @before_stack ||= superclass.before_stack.dup end
10
+ def self.after_stack; @after_stack ||= superclass.after_stack.dup end
11
+
12
+ def self.test_node; @test_node ||= test_tree end
13
+ def self.test_tree; @test_tree ||= Liza::TestTreePart::Extension.new nil, before_stack, after_stack end
14
+
15
+ #
16
+
17
+ def self.group *words, &block
18
+ raise ArgumentError, "No block given" unless block_given?
19
+ previous = test_node
20
+ @test_node = test_node.branch_out words
21
+ instance_exec &block
22
+ @test_node = previous
23
+ end
24
+
25
+ def self.test *words, &block
26
+ raise ArgumentError, "No block given" unless block_given?
27
+ test_node.add_test words, &block
28
+ end
29
+
30
+ def self.before &block
31
+ raise ArgumentError, "No block given" unless block_given?
32
+ test_node.add_before &block
33
+ end
34
+
35
+ def self.after &block
36
+ raise ArgumentError, "No block given" unless block_given?
37
+ test_node.add_after &block
38
+ end
39
+
40
+ end
41
+
42
+ extension do
43
+
44
+ def log *args
45
+ self.class.solder.log *args
46
+ end
47
+
48
+ def log_test_building?
49
+ Liza::Test.log_test_building?
50
+ end
51
+
52
+ attr_reader :tests, :parent, :children, :before_stack, :after_stack
53
+
54
+ def initialize parent, before_stack, after_stack
55
+ @parent = parent || self
56
+
57
+ @children, @tests = [], []
58
+ @before_top, @after_top = [], []
59
+
60
+ @before_stack = before_stack.push @before_top
61
+ @after_stack = after_stack.unshift @after_top
62
+
63
+ @parent.children << self if @parent != self
64
+ end
65
+
66
+ def initialize parent, before_stack, after_stack
67
+ @parent = parent || self
68
+
69
+ @children, @tests, @before_top, @after_top = [], [], [], []
70
+
71
+ @before_stack = before_stack.push @before_top
72
+ @after_stack = after_stack.unshift @after_top
73
+
74
+ @parent.children << self if @parent != self
75
+ end
76
+
77
+ def initialize parent, before_stack, after_stack
78
+ @parent = parent || self
79
+ @children, @tests = [], []
80
+ @parent.children << self if @parent != self
81
+
82
+ @before_top, @after_top = [], []
83
+ @before_stack = before_stack.push @before_top
84
+ @after_stack = after_stack.unshift @after_top
85
+ end
86
+
87
+ def initialize parent, before_stack, after_stack
88
+ @tests = []
89
+
90
+ @parent = parent || self
91
+ @children = []
92
+ @parent.children << self if @parent != self
93
+
94
+ @before_top, @after_top = [], []
95
+ @before_stack = before_stack.push @before_top
96
+ @after_stack = after_stack.unshift @after_top
97
+ end
98
+
99
+ def initialize parent, before_stack, after_stack
100
+ @tests = []
101
+ initialize_parenting parent
102
+ initialize_filters before_stack, after_stack
103
+ end
104
+
105
+ def initialize_parenting parent
106
+ @parent = parent || self
107
+ @children = []
108
+ @parent.children << self if @parent != self
109
+ end
110
+
111
+ def initialize_filters before_stack, after_stack
112
+ @before_top, @after_top = [], []
113
+ @before_stack = before_stack.push @before_top
114
+ @after_stack = after_stack.unshift @after_top
115
+ end
116
+
117
+ def add_before &block
118
+ log "add_before to ##{object_id} #{block}" if log_test_building?
119
+ @before_top.push block
120
+ end
121
+
122
+ def add_test words, &block
123
+ log "add_test to ##{object_id} #{words} #{block}" if log_test_building?
124
+ tests << [words, block]
125
+ end
126
+
127
+ def add_after &block
128
+ log "add_after to ##{object_id} #{block}" if log_test_building?
129
+ @after_top.push block
130
+ end
131
+
132
+ def branch_out words, &block
133
+ self.class.new self, before_stack.dup, after_stack.dup
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+ end
data/lib/liza/unit.rb CHANGED
@@ -7,6 +7,8 @@ module Liza
7
7
  App.connect_part self, key, system
8
8
  end
9
9
 
10
+ part :unit_procedure
11
+
10
12
  # SETTINGS
11
13
 
12
14
  def self.settings
@@ -0,0 +1,17 @@
1
+ class Liza::UnitProcedurePart < Liza::Part
2
+
3
+ insertion do
4
+ def self.procedure _label, &block
5
+ catch :procedure, &block
6
+ end
7
+
8
+ def self.proceed val = nil, &block
9
+ val = yield if val.nil? && block_given?
10
+ throw :procedure, val
11
+ end
12
+
13
+ def procedure(_label, &block)= self.class.procedure _label, &block
14
+ def proceed(...)= self.class.proceed(...)
15
+ end
16
+
17
+ end
@@ -0,0 +1,65 @@
1
+ class Liza::UnitProcedurePartTest < Liza::UnitTest
2
+
3
+ test :procedure_scopes_and_returns do
4
+ b = nil
5
+
6
+ w =
7
+ procedure "creates a new scope" do
8
+ @a = 1
9
+ b = 2
10
+ c = 3
11
+ assert true
12
+
13
+ proceed if true
14
+ raise "did not get here"
15
+ end
16
+
17
+ assert assertions > 0
18
+ assert w.nil?
19
+
20
+ x =
21
+ procedure "asserts old scope is not accessible" do
22
+ assert instance_variables.include? :@a
23
+ assert local_variables.include? :b
24
+ refute local_variables.include? :c
25
+
26
+ assert @a == 1
27
+ assert b == 2
28
+
29
+ proceed 100 if true
30
+ raise "did not get here"
31
+ end
32
+
33
+ assert x == 100
34
+
35
+ y =
36
+ procedure "asserts proceed calls can be lazy" do
37
+ proceed { "slow operation"; 200 } if true
38
+ raise "did not get here"
39
+ end
40
+
41
+ assert y == 200
42
+ end
43
+
44
+ test :procedure_rescue_and_ensure do
45
+ procedure "assert ensure works" do
46
+ @a = 1
47
+ ensure
48
+ @a = 2
49
+ end
50
+
51
+ assert @a == 2
52
+
53
+ procedure "assert rescue works" do
54
+ @a = [1]
55
+ raise "a runtime error!"
56
+ rescue RuntimeError
57
+ @a << 2
58
+ ensure
59
+ @a << 3
60
+ end
61
+
62
+ assert @a == [1, 2, 3]
63
+ end
64
+
65
+ end
data/lib/liza.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Liza
4
4
  class Error < StandardError; end
5
+ class ConstNotFound < Error; end
5
6
 
6
7
  #
7
8
 
@@ -27,6 +28,8 @@ module Liza
27
28
  return k if k
28
29
 
29
30
  nil
31
+ rescue NameError
32
+ raise ConstNotFound, name
30
33
  end
31
34
 
32
35
  # Checks each system, then Liza for Liza::Unit classes
@@ -46,6 +49,8 @@ module Liza
46
49
  end
47
50
 
48
51
  def const_check_systems name
52
+ App.systems.frozen? or return nil
53
+
49
54
  for k in App.systems.values.reverse
50
55
  next if not k.const_defined? name.to_sym
51
56
  kk = k.const(name) if k.constants.include? name
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Module
4
+
5
+ # /path/to/liza.rb
6
+ def source_location
7
+ Object.const_source_location name
8
+ end
9
+
10
+ # /path/to/liza
11
+ def source_location_radical
12
+ source_location[0][0..-4]
13
+ rescue
14
+ nil
15
+ end
16
+
17
+ end
@@ -3,10 +3,18 @@
3
3
  class String
4
4
  alias lpartition partition
5
5
 
6
- def camelize
7
- split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
6
+ def camelcase
7
+ split("_").map { |s| "#{s[0].to_s.upcase}#{s[1..-1]}" }.join("")
8
8
  end
9
9
 
10
+ alias camelize camelcase
11
+
12
+ def snakecase
13
+ gsub(/[A-Z\s-]/) { |s, t| "_#{s}" }[1..-1].to_s.downcase
14
+ end
15
+
16
+ alias snakefy snakecase
17
+
10
18
  def rjust_blanks length
11
19
  rjust length, " "
12
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lizarb
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/lizarb.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "colorize"
4
+ require "json"
4
5
  require "pathname"
5
6
  require "zeitwerk"
7
+ require "lerb"
6
8
 
7
9
  require_relative "lizarb/version"
8
10
 
@@ -11,7 +13,8 @@ module Lizarb
11
13
 
12
14
  #
13
15
 
14
- GEM_DIR = Gem::Specification.find_by_name("lizarb").gem_dir
16
+ SPEC = Gem::Specification.find_by_name("lizarb")
17
+ GEM_DIR = SPEC.gem_dir
15
18
  CUR_DIR = Dir.pwd
16
19
 
17
20
  IS_APP_DIR = File.file? "#{CUR_DIR}/app.rb"
@@ -36,7 +39,10 @@ module Lizarb
36
39
 
37
40
  require "#{APP_DIR}/app"
38
41
 
39
- VERSION
42
+ versions = {ruby: RUBY_VERSION, bundler: Bundler::VERSION, zeitwerk: Zeitwerk::VERSION, lizarb: VERSION}
43
+ bugs = SPEC.metadata["bug_tracker_uri"]
44
+ puts versions.to_s.green
45
+ puts "Report bugs at #{bugs}"
40
46
  end
41
47
 
42
48
  # called from "#{APP_DIR}/app"
@@ -65,4 +71,20 @@ module Lizarb
65
71
  : "#{GEM_DIR}/exe/Gemfile"
66
72
  end
67
73
 
74
+ # threads
75
+
76
+ def thread_object_id
77
+ Thread.current.object_id
78
+ end
79
+
80
+ @thread_ids = {thread_object_id => 0}
81
+ @thread_ids_mutex = Mutex.new
82
+
83
+ def thread_id
84
+ @thread_ids[thread_object_id] ||=
85
+ @thread_ids_mutex.synchronize do
86
+ @thread_ids.count
87
+ end
88
+ end
89
+
68
90
  end
@@ -0,0 +1,31 @@
1
+ class NetSystem
2
+ class Record < Liza::Controller
3
+
4
+ def self.inherited sub
5
+ super
6
+
7
+ return if sub.name.nil?
8
+ return if sub.name.end_with? "Record"
9
+ raise "please rename #{sub.name} to #{sub.name}Record"
10
+ end
11
+
12
+ def self.db database_id = nil
13
+ if database_id.nil?
14
+ db = get :db
15
+ if db
16
+ Liza.const(:NetBox).databases.get db
17
+ else
18
+ raise "please set a db to record #{self}"
19
+ end
20
+ else
21
+ valid = Liza.const(:NetBox).databases.settings.keys
22
+ if valid.include? database_id
23
+ set :db, database_id
24
+ else
25
+ raise "invalid db `#{database_id}`, valid options are #{valid}"
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -1,8 +1,8 @@
1
1
  class NetSystem
2
- class ModelTest < Liza::ControllerTest
2
+ class RecordTest < Liza::ControllerTest
3
3
 
4
4
  test :subject_class do
5
- assert subject_class == NetSystem::Model
5
+ assert subject_class == NetSystem::Record
6
6
  end
7
7
 
8
8
  test :settings do