lizarb 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +12 -13
  3. data/Rakefile +38 -0
  4. data/app/dev_box.rb +26 -4
  5. data/app/happy_box.rb +2 -2
  6. data/app/net/databases/sqlite_db_test.rb +5 -5
  7. data/app/net/records/app_record_test.rb +1 -1
  8. data/app/net/records/post_record_test.rb +1 -1
  9. data/app/net/records/user_record_test.rb +1 -1
  10. data/app/net_box.rb +9 -9
  11. data/app/web_box.rb +4 -4
  12. data/app.rb +6 -7
  13. data/{exe/Gemfile → app_global.gemfile.rb} +2 -0
  14. data/app_global.gemfile.rb.lock +19 -0
  15. data/app_global.rb +4 -0
  16. data/{app → app_new}/dev/benches/loops_bench.rb +3 -2
  17. data/{app/dev/generators/bench_generator_test.rb → app_new/dev/benches/loops_bench_test.rb} +2 -2
  18. data/app_new/dev/benches/objects_bench.rb +83 -0
  19. data/{app/dev/generators/record_generator_test.rb → app_new/dev/benches/objects_bench_test.rb} +2 -2
  20. data/app_new/dev/benches/sorted_bench.rb +54 -0
  21. data/app_new/dev/benches/sorted_bench_test.rb +12 -0
  22. data/app_new/dev/benches/variables_bench.rb +55 -0
  23. data/{app/dev/generators/command_generator_test.rb → app_new/dev/benches/variables_bench_test.rb} +2 -2
  24. data/{app → app_new}/dev/commands/calculator_command.rb +1 -1
  25. data/{app → app_new}/dev/commands/circle_command.rb +1 -1
  26. data/{app → app_new}/dev/commands/narrative_method_command.rb +5 -7
  27. data/{app → app_new}/dev/commands/quadratic_command.rb +1 -1
  28. data/app_new/dev_box.rb +14 -0
  29. data/app_new.rb +15 -0
  30. data/exe/lizarb +9 -1
  31. data/lib/app.rb +27 -95
  32. data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +23 -18
  33. data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +9 -11
  34. data/lib/dev_system/dev/controllers/bench.rb +1 -9
  35. data/lib/dev_system/dev/controllers/bench_test.rb +8 -10
  36. data/lib/dev_system/dev/controllers/command/bench_command.rb +19 -22
  37. data/lib/dev_system/dev/controllers/command/bench_command_test.rb +8 -10
  38. data/lib/dev_system/dev/controllers/command/generate_command.rb +5 -31
  39. data/lib/dev_system/dev/controllers/command/generate_command_test.rb +8 -10
  40. data/lib/dev_system/dev/controllers/command/new_command.rb +9 -0
  41. data/lib/dev_system/dev/controllers/command/new_command_test.rb +7 -0
  42. data/lib/dev_system/dev/controllers/command/not_found_command.rb +37 -18
  43. data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +8 -10
  44. data/lib/dev_system/dev/controllers/command/terminal_command.rb +12 -14
  45. data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +8 -10
  46. data/lib/dev_system/dev/controllers/command/test_command.rb +64 -53
  47. data/lib/dev_system/dev/controllers/command/test_command_test.rb +8 -10
  48. data/lib/dev_system/dev/controllers/command.rb +9 -15
  49. data/lib/dev_system/dev/controllers/command_test.rb +8 -10
  50. data/lib/dev_system/dev/controllers/generator.rb +5 -7
  51. data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +33 -37
  52. data/lib/dev_system/dev/controllers/generator_test.rb +8 -10
  53. data/{app/dev/generators/bench_generator/bench.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller.rb.erb} +1 -2
  54. data/{app/dev/generators/bench_generator/bench_test.rb.erb → lib/dev_system/dev/controllers/generators/bench_generator/controller_test.rb.erb} +2 -2
  55. data/lib/dev_system/dev/controllers/generators/bench_generator.rb +12 -0
  56. data/lib/dev_system/dev/controllers/generators/bench_generator_test.rb +12 -0
  57. data/lib/dev_system/dev/controllers/generators/command_generator/controller.rb.erb +41 -0
  58. data/{app/dev/generators/command_generator/command_test.rb.erb → lib/dev_system/dev/controllers/generators/command_generator/controller_test.rb.erb} +2 -2
  59. data/lib/dev_system/dev/controllers/generators/command_generator.rb +19 -0
  60. data/lib/dev_system/dev/controllers/generators/command_generator_test.rb +12 -0
  61. data/lib/dev_system/dev/controllers/generators/controller_generator.rb +97 -0
  62. data/lib/dev_system/dev/controllers/generators/controller_generator_test.rb +12 -0
  63. data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +1 -1
  64. data/lib/dev_system/dev/controllers/generators/new_generator.rb +117 -0
  65. data/lib/dev_system/dev/controllers/generators/new_generator_test.rb +12 -0
  66. data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +27 -17
  67. data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +8 -10
  68. data/{app/dev → lib/dev_system/dev/controllers}/generators/record_generator.rb +1 -1
  69. data/lib/dev_system/dev/controllers/generators/record_generator_test.rb +12 -0
  70. data/{app/dev → lib/dev_system/dev/controllers}/generators/request_generator.rb +2 -2
  71. data/lib/dev_system/dev/controllers/generators/request_generator_test.rb +12 -0
  72. data/lib/dev_system/dev/controllers/log.rb +3 -0
  73. data/{app/dev/generators/request_generator_test.rb → lib/dev_system/dev/controllers/log_test.rb} +2 -2
  74. data/lib/dev_system/dev/controllers/shell.rb +22 -0
  75. data/lib/dev_system/dev/controllers/shell_test.rb +25 -0
  76. data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +15 -11
  77. data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +8 -10
  78. data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +6 -8
  79. data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +8 -10
  80. data/lib/dev_system/dev/controllers/terminal.rb +11 -13
  81. data/lib/dev_system/dev/controllers/terminal_test.rb +8 -10
  82. data/lib/dev_system/dev/dev_box.rb +27 -16
  83. data/lib/dev_system/dev/dev_box_test.rb +12 -14
  84. data/lib/dev_system/dev/panels/bench_panel.rb +3 -0
  85. data/lib/dev_system/dev/panels/bench_panel_test.rb +12 -0
  86. data/lib/dev_system/dev/panels/command_panel.rb +59 -18
  87. data/lib/dev_system/dev/panels/command_panel_test.rb +43 -20
  88. data/lib/dev_system/dev/panels/generator_panel.rb +73 -0
  89. data/lib/dev_system/dev/panels/generator_panel_test.rb +46 -0
  90. data/lib/dev_system/dev/panels/log_panel.rb +9 -6
  91. data/lib/dev_system/dev/panels/log_panel_test.rb +11 -13
  92. data/lib/dev_system/dev/panels/shell_panel.rb +3 -0
  93. data/lib/dev_system/dev/panels/shell_panel_test.rb +12 -0
  94. data/lib/dev_system/dev/panels/terminal_panel.rb +3 -0
  95. data/lib/dev_system/dev/panels/terminal_panel_test.rb +12 -0
  96. data/lib/happy_system/happy/controllers/axo.rb +4 -5
  97. data/lib/happy_system/happy/happy_box.rb +5 -9
  98. data/lib/happy_system/happy/happy_box_test.rb +11 -13
  99. data/lib/happy_system/happy/panels/axo_panel.rb +1 -3
  100. data/lib/lerb.rb +95 -49
  101. data/lib/liza/base/box.rb +76 -26
  102. data/lib/liza/base/box_test.rb +7 -9
  103. data/lib/liza/base/controller.rb +19 -21
  104. data/lib/liza/base/controller_test.rb +7 -9
  105. data/lib/liza/base/panel.rb +40 -27
  106. data/lib/liza/base/panel_test.rb +36 -12
  107. data/lib/liza/base_parts/controller_renderer_part.rb +1 -1
  108. data/lib/liza/meta/part.rb +12 -14
  109. data/lib/liza/meta/part_extension.rb +14 -16
  110. data/lib/liza/meta/part_test.rb +4 -6
  111. data/lib/liza/meta/system.rb +12 -14
  112. data/lib/liza/meta/system_test.rb +8 -10
  113. data/lib/liza/ruby_test.rb +4 -6
  114. data/lib/liza/ruby_tests/module_test.rb +3 -3
  115. data/lib/liza/test/test.rb +7 -10
  116. data/lib/liza/test/test_test.rb +160 -157
  117. data/lib/liza/test_parts/test_assertions_advanced_part.rb +102 -104
  118. data/lib/liza/test_parts/test_assertions_part.rb +81 -83
  119. data/lib/liza/test_parts/test_dsl_part.rb +47 -49
  120. data/lib/liza/test_parts/test_log_part.rb +88 -90
  121. data/lib/liza/test_parts/test_subject_part.rb +16 -18
  122. data/lib/liza/test_parts/test_tree_part.rb +73 -120
  123. data/lib/liza/unit.rb +105 -107
  124. data/lib/liza/unit_parts/unit_procedure_part_test.rb +9 -9
  125. data/lib/liza/unit_parts/unit_settings_part.rb +76 -0
  126. data/lib/liza/unit_parts/unit_settings_part_test.rb +3 -0
  127. data/lib/liza/unit_test.rb +80 -71
  128. data/lib/liza.rb +10 -1
  129. data/lib/lizarb/ruby/module.rb +1 -1
  130. data/lib/lizarb/version.rb +1 -1
  131. data/lib/lizarb.rb +247 -23
  132. data/lib/net_system/dev/net_command.rb +15 -17
  133. data/lib/net_system/net/controllers/client/redis_client.rb +19 -21
  134. data/lib/net_system/net/controllers/client/redis_client_test.rb +20 -22
  135. data/lib/net_system/net/controllers/client/sqlite_client.rb +19 -21
  136. data/lib/net_system/net/controllers/client/sqlite_client_test.rb +20 -22
  137. data/lib/net_system/net/controllers/client.rb +1 -3
  138. data/lib/net_system/net/controllers/client_test.rb +8 -10
  139. data/lib/net_system/net/controllers/database/redis_db.rb +6 -8
  140. data/lib/net_system/net/controllers/database/redis_db_test.rb +15 -17
  141. data/lib/net_system/net/controllers/database/sqlite_db.rb +6 -8
  142. data/lib/net_system/net/controllers/database/sqlite_db_test.rb +15 -17
  143. data/lib/net_system/net/controllers/database.rb +21 -23
  144. data/lib/net_system/net/controllers/database_test.rb +8 -10
  145. data/lib/net_system/net/controllers/record.rb +21 -23
  146. data/lib/net_system/net/controllers/record_test.rb +8 -10
  147. data/lib/net_system/net/net_box.rb +9 -16
  148. data/lib/net_system/net/net_box_test.rb +12 -14
  149. data/lib/net_system/net/panels/client_panel.rb +1 -3
  150. data/lib/net_system/net/panels/client_panel_test.rb +11 -13
  151. data/lib/net_system/net/panels/database_panel.rb +6 -8
  152. data/lib/net_system/net/panels/database_panel_test.rb +11 -13
  153. data/lib/web_system/dev/rack_command.rb +20 -18
  154. data/lib/web_system/dev/request_command.rb +8 -22
  155. data/lib/web_system/dev/web_command.rb +6 -8
  156. data/lib/web_system/web/controllers/rack.rb +4 -6
  157. data/lib/web_system/web/controllers/rack_test.rb +11 -13
  158. data/lib/web_system/web/controllers/request/client_error_request.rb +9 -11
  159. data/lib/web_system/web/controllers/request/not_found_request.rb +9 -11
  160. data/lib/web_system/web/controllers/request/server_error_request.rb +10 -12
  161. data/lib/web_system/web/controllers/request.rb +1 -3
  162. data/lib/web_system/web/controllers/request_test.rb +11 -13
  163. data/lib/web_system/web/panels/rack_panel.rb +37 -39
  164. data/lib/web_system/web/panels/rack_panel_test.rb +8 -10
  165. data/lib/web_system/web/panels/request_panel.rb +53 -57
  166. data/lib/web_system/web/panels/request_panel_test.rb +1 -1
  167. data/lib/web_system/web/web_box.rb +12 -18
  168. data/lib/web_system/web/web_box_test.rb +11 -13
  169. data/lizarb.gemspec +1 -1
  170. metadata +54 -44
  171. data/.ruby-version +0 -1
  172. data/app/dev/benches/app_bench.rb +0 -5
  173. data/app/dev/benches/app_bench_test.rb +0 -7
  174. data/app/dev/benches/loops_bench_test.rb +0 -11
  175. data/app/dev/commands/app_command.rb +0 -5
  176. data/app/dev/commands/app_command_test.rb +0 -7
  177. data/app/dev/commands/new_command.rb +0 -9
  178. data/app/dev/commands/new_command_test.rb +0 -7
  179. data/app/dev/generators/bench_generator.rb +0 -18
  180. data/app/dev/generators/command_generator/command.rb.erb +0 -26
  181. data/app/dev/generators/command_generator.rb +0 -18
  182. data/app_new/.gitignore +0 -4
  183. data/app_new/Gemfile +0 -31
  184. data/app_new/Procfile +0 -3
  185. data/exe/Gemfile.lock +0 -13
  186. data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +0 -60
  187. data/lib/dev_system/dev/controllers/command/echo_command.rb +0 -11
  188. data/lib/dev_system/dev/controllers/command/echo_command_test.rb +0 -14
  189. data/lib/dev_system/dev/controllers/command/version_command.rb +0 -9
  190. data/lib/dev_system/dev/controllers/command/version_command_test.rb +0 -14
  191. data/lib/dev_system/dev/controllers/generators/app_generator.rb +0 -96
  192. data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +0 -14
  193. /data/{app → app_new}/dev/commands/calculator_command_test.rb +0 -0
  194. /data/{app → app_new}/dev/commands/circle_command_test.rb +0 -0
  195. /data/{app → app_new}/dev/commands/narrative_method_command_test.rb +0 -0
  196. /data/{app → app_new}/dev/commands/quadratic_command_test.rb +0 -0
@@ -1,139 +1,92 @@
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
-
1
+ class Liza::TestTreePart < Liza::Part
2
+
3
+ insertion do
4
+
5
+ @before_stack = []
6
+ @after_stack = []
7
+
8
+ def self.before_stack; @before_stack ||= superclass.before_stack.dup end
9
+ def self.after_stack; @after_stack ||= superclass.after_stack.dup end
10
+
11
+ def self.test_node; @test_node ||= test_tree end
12
+ def self.test_tree; @test_tree ||= Liza::TestTreePart::Extension.new nil, before_stack, after_stack end
13
+
14
+ #
15
+
16
+ def self.group *words, &block
17
+ raise ArgumentError, "No block given" unless block_given?
18
+ previous = test_node
19
+ @test_node = test_node.branch_out words
20
+ instance_exec(&block)
21
+ @test_node = previous
40
22
  end
41
23
 
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
24
+ def self.test *words, &block
25
+ raise ArgumentError, "No block given" unless block_given?
26
+ test_node.add_test words, &block
27
+ end
76
28
 
77
- def initialize parent, before_stack, after_stack
78
- @parent = parent || self
79
- @children, @tests = [], []
80
- @parent.children << self if @parent != self
29
+ def self.before &block
30
+ raise ArgumentError, "No block given" unless block_given?
31
+ test_node.add_before(&block)
32
+ end
81
33
 
82
- @before_top, @after_top = [], []
83
- @before_stack = before_stack.push @before_top
84
- @after_stack = after_stack.unshift @after_top
85
- end
34
+ def self.after &block
35
+ raise ArgumentError, "No block given" unless block_given?
36
+ test_node.add_after(&block)
37
+ end
86
38
 
87
- def initialize parent, before_stack, after_stack
88
- @tests = []
39
+ end
89
40
 
90
- @parent = parent || self
91
- @children = []
92
- @parent.children << self if @parent != self
41
+ extension do
42
+
43
+ def log *args
44
+ self.class.solder.log(*args)
45
+ end
93
46
 
94
- @before_top, @after_top = [], []
95
- @before_stack = before_stack.push @before_top
96
- @after_stack = after_stack.unshift @after_top
97
- end
47
+ def log_test_building?
48
+ Liza::Test.log_test_building?
49
+ end
98
50
 
99
- def initialize parent, before_stack, after_stack
100
- @tests = []
101
- initialize_parenting parent
102
- initialize_filters before_stack, after_stack
103
- end
51
+ attr_reader :tests, :parent, :children, :before_stack, :after_stack
104
52
 
105
- def initialize_parenting parent
106
- @parent = parent || self
107
- @children = []
108
- @parent.children << self if @parent != self
109
- end
53
+ def initialize parent, before_stack, after_stack
54
+ @tests = []
55
+ initialize_parenting parent
56
+ initialize_filters before_stack, after_stack
57
+ end
110
58
 
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
59
+ def initialize_parenting parent
60
+ @parent = parent || self
61
+ @children = []
62
+ @parent.children << self if @parent != self
63
+ end
116
64
 
117
- def add_before &block
118
- log "add_before to ##{object_id} #{block}" if log_test_building?
119
- @before_top.push block
120
- end
65
+ def initialize_filters before_stack, after_stack
66
+ @before_top, @after_top = [], []
67
+ @before_stack = before_stack.push @before_top
68
+ @after_stack = after_stack.unshift @after_top
69
+ end
121
70
 
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
71
+ def add_before &block
72
+ log "add_before to ##{object_id} #{block}" if log_test_building?
73
+ @before_top.push block
74
+ end
126
75
 
127
- def add_after &block
128
- log "add_after to ##{object_id} #{block}" if log_test_building?
129
- @after_top.push block
130
- end
76
+ def add_test words, &block
77
+ log "add_test to ##{object_id} #{words} #{block}" if log_test_building?
78
+ tests << [words, block]
79
+ end
131
80
 
132
- def branch_out words, &block
133
- self.class.new self, before_stack.dup, after_stack.dup
134
- end
81
+ def add_after &block
82
+ log "add_after to ##{object_id} #{block}" if log_test_building?
83
+ @after_top.push block
84
+ end
135
85
 
86
+ def branch_out words, &block
87
+ self.class.new self, before_stack.dup, after_stack.dup
136
88
  end
137
89
 
138
90
  end
91
+
139
92
  end
data/lib/liza/unit.rb CHANGED
@@ -1,151 +1,149 @@
1
- module Liza
2
- class Unit
1
+ class Liza::Unit
3
2
 
4
- # PARTS
3
+ # PARTS
5
4
 
6
- def self.part key, system: nil
7
- App.connect_part self, key, system
8
- end
5
+ def self.part key, system: nil
6
+ App.connect_part self, key, system
7
+ end
9
8
 
10
- part :unit_procedure
9
+ # CONST MISSING
11
10
 
12
- # SETTINGS
11
+ if Lizarb.ruby_supports_raise_cause?
13
12
 
14
- def self.settings
15
- @settings ||= {}
13
+ def self.const_missing name
14
+ Liza.const name
15
+ rescue Liza::ConstNotFound
16
+ raise NameError, "uninitialized constant #{name}", caller[1..], cause: nil
16
17
  end
17
18
 
18
- def self.get key
19
- return settings[key] if settings.has_key? key
19
+ else
20
20
 
21
- found = nil
21
+ def self.const_missing name
22
+ Liza.const name
23
+ rescue Liza::ConstNotFound
24
+ raise NameError, "uninitialized constant #{name}", caller[1..]
25
+ end
22
26
 
23
- for klass in ancestors
24
- break unless klass.respond_to? :settings
27
+ end
25
28
 
26
- if klass.settings.has_key? key
27
- found = klass.settings[key]
29
+ part :unit_procedure
30
+ part :unit_settings
28
31
 
29
- break
30
- end
31
- end
32
+ # LOG
32
33
 
33
- found = settings[key] = found.dup if found.is_a? Enumerable
34
+ LOG_LEVELS = {
35
+ :higher => 2,
36
+ :high => 1,
37
+ :normal => 0,
38
+ :low => -1,
39
+ :lower => -2,
40
+ }
34
41
 
35
- found
36
- end
42
+ set :log_level, :normal
43
+ set :log_color, :white
37
44
 
38
- def self.set key, value
39
- settings[key] = value
40
- value
41
- end
45
+ # NOTE: improve logs performance and readability
42
46
 
43
- def self.add list, key = nil, value
44
- if key
45
- fetch(list) { Hash.new }[key] = value
46
- else
47
- fetch(list) { Set.new } << value
48
- end
49
- end
47
+ LOG_JUST = 60
50
48
 
51
- def self.fetch key, &block
52
- x = get key
53
- x ||= set key, instance_eval(&block)
54
- x
55
- end
49
+ def self.build_log_sidebar_for source, method_key, method_sep, panel_key: nil
50
+ source = (source.is_a? Class) ? source : source.class
51
+ source_color = source.log_color
52
+ source = source.to_s
56
53
 
57
- def settings
58
- @settings ||= {}
59
- end
60
-
61
- def get key
62
- return settings[key] if settings.has_key? key
63
-
64
- self.class.get key
65
- end
54
+ s = source.bold.colorize(source_color)
55
+ s << "[:#{panel_key}]" if panel_key
56
+ s << "#{method_sep}#{method_key}"
57
+ s.ljust(LOG_JUST)
58
+ end
66
59
 
67
- def set key, value
68
- settings[key] = value
69
- end
60
+ # NOTE: This code needs to be optimized.
61
+ def self._log_extract_method_name kaller
62
+ kaller.each do |s|
63
+ t = s.match(/`(.*)'/)[1]
70
64
 
71
- def add list, key = nil, value
72
- if key
73
- fetch(list) { Hash.new }[key] = value
74
- else
75
- fetch(list) { Set.new } << value
76
- end
65
+ next if t.include? " in <class:"
66
+ return t.split(" ").last if t.include? " in "
67
+
68
+ next if t == "log"
69
+ next if t == "each"
70
+ next if t == "map"
71
+ next if t == "with_index"
72
+ next if t == "instance_exec"
73
+ next if t.start_with? "_"
74
+ return t
77
75
  end
78
76
 
79
- def fetch key, &block
80
- x = get key
81
- x ||= set key, eval(&block)
82
- x
83
- end
84
-
85
- # LOG
86
-
87
- LOG_LEVELS = {
88
- :higher => 2,
89
- :high => 1,
90
- :normal => 0,
91
- :low => -1,
92
- :lower => -2,
93
- }
77
+ raise "there's something wrong with kaller"
78
+ end
94
79
 
95
- set :log_level, :normal
96
- set :log_color, :white
80
+ def _log_extract_method_name kaller
81
+ self.class._log_extract_method_name kaller
82
+ end
97
83
 
98
- #
84
+ def self.log log_level = :normal, string, kaller: caller
85
+ raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
86
+ return unless log_level? log_level
99
87
 
100
- LOG_JUST = 40
88
+ method_key = _log_extract_method_name kaller
89
+ source = Liza::Unit.build_log_sidebar_for self, method_key, ":"
101
90
 
102
- def self.log log_level = :normal, string
103
- raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
104
- return unless log_level? log_level
91
+ DevBox[:log].call "#{source} #{string}"
92
+ end
105
93
 
106
- source = (self.is_a? Class) ? self : self.class
107
- source = source.to_s.ljust(LOG_JUST).bold.colorize(source.log_color)
94
+ def log log_level = :normal, string, kaller: caller
95
+ raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
96
+ return unless log_level? log_level
108
97
 
109
- string = "#{source} #{string}"
98
+ method_key = _log_extract_method_name kaller
110
99
 
111
- DevBox.logs.call string
100
+ case self
101
+ when Liza::Panel
102
+ source = Liza::Unit.build_log_sidebar_for box, method_key, ".", panel_key: @key
103
+ when Liza::UnitTest
104
+ source = Liza::Unit.build_log_sidebar_for self, " ", " "
105
+ else
106
+ source = Liza::Unit.build_log_sidebar_for self, method_key, "#"
112
107
  end
113
108
 
114
- def self.log_level
115
- get(:log_level) || :normal
116
- end
109
+ DevBox[:log].call "#{source} #{string}"
110
+ end
117
111
 
118
- def self.log_level? log_level = :normal
119
- # TODO
120
- true
121
- end
112
+ #
122
113
 
123
- def self.log_color
124
- (get(:system) || self).get :log_color
125
- end
114
+ def self.log_level
115
+ get(:log_level) || :normal
116
+ end
126
117
 
127
- def self.log?(log_level = :normal)= log_level? log_level
128
- def log(...)= self.class.log(...)
129
- def log_level(...)= self.class.log_level(...)
130
- def log?(...)= self.class.log?(...)
131
- def log_level?(...)= self.class.log_level?(...)
132
- def log_color(...)= self.class.log_color(...)
118
+ def self.log_level? log_level = :normal
119
+ # TODO
120
+ true
121
+ end
133
122
 
134
- # SYSTEM
123
+ def self.log_color
124
+ (get(:system) || self).get :log_color
125
+ end
126
+
127
+ def self.log?(log_level = :normal)= log_level? log_level
128
+ def log_level(...)= self.class.log_level(...)
129
+ def log?(...)= self.class.log?(...)
130
+ def log_level?(...)= self.class.log_level?(...)
131
+ def log_color(...)= self.class.log_color(...)
135
132
 
136
- def self.inherited_explicitly_sets_system
133
+ # SYSTEM
137
134
 
138
- def self.inherited sub
139
- super
135
+ def self.inherited_explicitly_sets_system
140
136
 
141
- return unless sub.name.to_s.include? "::"
137
+ def self.inherited sub
138
+ super
142
139
 
143
- system = Object.const_get sub.first_namespace
140
+ return unless sub.name.to_s.include? "::"
144
141
 
145
- sub.set :system, system
146
- end
142
+ system = Object.const_get sub.first_namespace
147
143
 
144
+ sub.set :system, system
148
145
  end
149
146
 
150
147
  end
148
+
151
149
  end
@@ -7,7 +7,6 @@ class Liza::UnitProcedurePartTest < Liza::UnitTest
7
7
  procedure "creates a new scope" do
8
8
  @a = 1
9
9
  b = 2
10
- c = 3
11
10
  assert true
12
11
 
13
12
  proceed if true
@@ -21,7 +20,6 @@ class Liza::UnitProcedurePartTest < Liza::UnitTest
21
20
  procedure "asserts old scope is not accessible" do
22
21
  assert instance_variables.include? :@a
23
22
  assert local_variables.include? :b
24
- refute local_variables.include? :c
25
23
 
26
24
  assert @a == 1
27
25
  assert b == 2
@@ -32,13 +30,15 @@ class Liza::UnitProcedurePartTest < Liza::UnitTest
32
30
 
33
31
  assert x == 100
34
32
 
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
33
+ y = procedure "asserts proceed calls can be lazy" do
34
+ proceed do
35
+ puts "slow operation"
36
+ 200
37
+ end if true
38
+ raise "did not get here"
39
+ end
40
+
41
+ assert y == 200
42
42
  end
43
43
 
44
44
  test :procedure_rescue_and_ensure do
@@ -0,0 +1,76 @@
1
+ class Liza::UnitSettingsPart < Liza::Part
2
+
3
+ insertion do
4
+ def self.settings
5
+ @settings ||= {}
6
+ end
7
+
8
+ def self.get key
9
+ return settings[key] if settings.has_key? key
10
+
11
+ found = nil
12
+
13
+ for klass in ancestors
14
+ break unless klass.respond_to? :settings
15
+
16
+ if klass.settings.has_key? key
17
+ found = klass.settings[key]
18
+
19
+ break
20
+ end
21
+ end
22
+
23
+ found = settings[key] = found.dup if found.is_a? Enumerable
24
+
25
+ found
26
+ end
27
+
28
+ def self.set key, value
29
+ settings[key] = value
30
+ value
31
+ end
32
+
33
+ def self.add list, key = nil, value
34
+ if key
35
+ fetch(list) { Hash.new }[key] = value
36
+ else
37
+ fetch(list) { Set.new } << value
38
+ end
39
+ end
40
+
41
+ def self.fetch key, &block
42
+ x = get key
43
+ x ||= set key, instance_eval(&block)
44
+ x
45
+ end
46
+
47
+ def settings
48
+ @settings ||= {}
49
+ end
50
+
51
+ def get key
52
+ return settings[key] if settings.has_key? key
53
+
54
+ self.class.get key
55
+ end
56
+
57
+ def set key, value
58
+ settings[key] = value
59
+ end
60
+
61
+ def add list, key = nil, value
62
+ if key
63
+ fetch(list) { Hash.new }[key] = value
64
+ else
65
+ fetch(list) { Set.new } << value
66
+ end
67
+ end
68
+
69
+ def fetch key, &block
70
+ x = get key
71
+ x ||= set key, eval(&block)
72
+ x
73
+ end
74
+ end
75
+
76
+ end
@@ -0,0 +1,3 @@
1
+ class Liza::UnitSettingsPartTest < Liza::UnitTest
2
+
3
+ end