lizarb 0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -2
- data/Gemfile +22 -2
- data/Gemfile.lock +52 -0
- data/README.md +88 -12
- data/app/dev/benches/app_bench.rb +5 -0
- data/app/dev/benches/app_bench_test.rb +7 -0
- data/app/dev/benches/loops_bench.rb +148 -0
- data/app/dev/benches/loops_bench_test.rb +11 -0
- data/app/dev/commands/app_command.rb +5 -0
- data/app/dev/commands/app_command_test.rb +7 -0
- data/app/dev/commands/example_command.rb +57 -0
- data/app/dev/commands/example_command_test.rb +43 -0
- data/app/dev/commands/macro_child_command.rb +32 -0
- data/app/dev/commands/macro_child_command_test.rb +7 -0
- data/app/dev/commands/macro_parent_command.rb +70 -0
- data/app/dev/commands/macro_parent_command_test.rb +7 -0
- data/app/dev/commands/my_command.rb +7 -0
- data/app/dev/commands/my_command_test.rb +7 -0
- data/app/dev/commands/new_command.rb +9 -0
- data/app/dev/commands/new_command_test.rb +7 -0
- data/app/dev/generators/bench_generator.rb +67 -0
- data/app/dev/generators/bench_generator_test.rb +12 -0
- data/app/dev/generators/command_generator.rb +51 -0
- data/app/dev/generators/command_generator_test.rb +12 -0
- data/app/dev/generators/model_generator.rb +46 -0
- data/app/dev/generators/model_generator_test.rb +12 -0
- data/app/dev/generators/request_generator.rb +63 -0
- data/app/dev/generators/request_generator_test.rb +12 -0
- data/app/dev_box.rb +13 -0
- data/app/happy/axos/axo.rb +50 -0
- data/app/happy_box.rb +8 -0
- data/app/net/databases/redis_db.rb +5 -0
- data/app/net/databases/redis_db_test.rb +12 -0
- data/app/net/databases/sqlite_db.rb +11 -0
- data/app/net/databases/sqlite_db_test.rb +12 -0
- data/app/net/models/app_model.rb +20 -0
- data/app/net/models/app_model_test.rb +8 -0
- data/app/net/models/post_model.rb +4 -0
- data/app/net/models/post_model_test.rb +8 -0
- data/app/net/models/user_model.rb +4 -0
- data/app/net/models/user_model_test.rb +8 -0
- data/app/net_box.rb +21 -0
- data/app/web/requests/api_request.rb +61 -0
- data/app/web/requests/api_request_test.rb +31 -0
- data/app/web/requests/app_request.rb +5 -0
- data/app/web/requests/app_request_test.rb +7 -0
- data/app/web/requests/assets_request.rb +71 -0
- data/app/web/requests/assets_request_test.rb +33 -0
- data/app/web/requests/root_request.rb +55 -0
- data/app/web/requests/root_request_test.rb +31 -0
- data/app/web_box.rb +8 -0
- data/app.code.env +11 -0
- data/app.env +11 -0
- data/app.rb +17 -0
- data/app_new/.gitignore +4 -0
- data/app_new/Gemfile +31 -0
- data/app_new/Procfile +3 -0
- data/exe/Gemfile +3 -0
- data/exe/Gemfile.lock +13 -0
- data/exe/liza +3 -0
- data/exe/lizarb +11 -0
- data/lib/app.rb +200 -0
- data/lib/dev_system/dev/controllers/bench.rb +11 -0
- data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
- data/lib/dev_system/dev/controllers/bench_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/bench_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/dev_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/dev_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/echo_command.rb +11 -0
- data/lib/dev_system/dev/controllers/command/echo_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/generate_command.rb +23 -0
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +70 -0
- data/lib/dev_system/dev/controllers/command/test_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/version_command.rb +9 -0
- data/lib/dev_system/dev/controllers/command/version_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command.rb +19 -0
- data/lib/dev_system/dev/controllers/command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generator.rb +11 -0
- data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
- data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +71 -0
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell/file_shell.rb +29 -0
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell.rb +19 -0
- data/lib/dev_system/dev/controllers/shell_test.rb +13 -0
- data/lib/dev_system/dev/controllers/terminal/irb_terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
- data/lib/dev_system/dev/dev_box.rb +22 -0
- data/lib/dev_system/dev/dev_box_test.rb +19 -0
- data/lib/dev_system/dev/panels/command_panel.rb +10 -0
- data/lib/dev_system/dev/panels/command_panel_test.rb +23 -0
- data/lib/dev_system/dev/panels/log_panel.rb +10 -0
- data/lib/dev_system/dev/panels/log_panel_test.rb +18 -0
- data/lib/dev_system.rb +8 -0
- data/lib/happy_system/dev/happy_command.rb +11 -0
- data/lib/happy_system/happy/controllers/axo.rb +8 -0
- data/lib/happy_system/happy/happy_box.rb +12 -0
- data/lib/happy_system/happy/happy_box_test.rb +18 -0
- data/lib/happy_system/happy/panels/axo_panel.rb +5 -0
- data/lib/{viral.rb → happy_system.rb} +7 -3
- data/lib/liza/base/box.rb +40 -0
- data/lib/liza/base/box_test.rb +12 -0
- data/lib/liza/base/controller.rb +27 -0
- data/lib/liza/base/controller_test.rb +12 -0
- data/lib/liza/base/panel.rb +38 -0
- data/lib/liza/base/panel_test.rb +16 -0
- data/lib/liza/meta/part.rb +19 -0
- data/lib/liza/meta/part_extension.rb +13 -0
- data/lib/liza/meta/part_test.rb +8 -0
- data/lib/liza/meta/system.rb +20 -0
- data/lib/liza/meta/system_test.rb +13 -0
- data/lib/liza/test/test.rb +11 -0
- data/lib/liza/test/test_test.rb +108 -0
- data/lib/liza/test_parts/test_assertions_part.rb +110 -0
- data/lib/liza/test_parts/test_context_part.rb +81 -0
- data/lib/liza/test_parts/test_dsl_part.rb +122 -0
- data/lib/liza/test_parts/test_subject_part.rb +24 -0
- data/lib/liza/unit.rb +149 -0
- data/lib/liza/unit_test.rb +79 -0
- data/lib/liza.rb +62 -0
- data/lib/lizarb/ruby/class.rb +17 -0
- data/lib/lizarb/ruby/proc.rb +12 -0
- data/lib/lizarb/ruby/string.rb +25 -0
- data/lib/lizarb/ruby/time.rb +9 -0
- data/lib/{viral → lizarb}/version.rb +2 -2
- data/lib/lizarb.rb +68 -0
- data/lib/net_system/dev/net_command.rb +24 -0
- data/lib/net_system/net/controllers/client/redis_client.rb +28 -0
- data/lib/net_system/net/controllers/client/redis_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client/sqlite_client.rb +28 -0
- data/lib/net_system/net/controllers/client/sqlite_client_test.rb +29 -0
- data/lib/net_system/net/controllers/client.rb +5 -0
- data/lib/net_system/net/controllers/client_test.rb +14 -0
- data/lib/net_system/net/controllers/database/redis_db.rb +11 -0
- data/lib/net_system/net/controllers/database/redis_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database/sqlite_db.rb +11 -0
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +23 -0
- data/lib/net_system/net/controllers/database.rb +33 -0
- data/lib/net_system/net/controllers/database_test.rb +14 -0
- data/lib/net_system/net/controllers/model.rb +31 -0
- data/lib/net_system/net/controllers/model_test.rb +14 -0
- data/lib/net_system/net/net_box.rb +20 -0
- data/lib/net_system/net/net_box_test.rb +19 -0
- data/lib/net_system/net/panels/client_panel.rb +5 -0
- data/lib/net_system/net/panels/client_panel_test.rb +18 -0
- data/lib/net_system/net/panels/database_panel.rb +12 -0
- data/lib/net_system/net/panels/database_panel_test.rb +18 -0
- data/lib/net_system.rb +3 -0
- data/lib/web_system/dev/web_command.rb +42 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +18 -0
- data/lib/web_system/web/controllers/request/not_found_request.rb +18 -0
- data/lib/web_system/web/controllers/request/server_error_request.rb +20 -0
- data/lib/web_system/web/controllers/request.rb +5 -0
- data/lib/web_system/web/controllers/request_test.rb +18 -0
- data/lib/web_system/web/panels/request_panel.rb +55 -0
- data/lib/web_system/web/panels/request_panel_test.rb +14 -0
- data/lib/web_system/web/web_box.rb +12 -0
- data/lib/web_system/web/web_box_test.rb +18 -0
- data/lib/web_system.rb +5 -0
- data/lizarb.gemspec +44 -0
- data/sig/{viral.rbs → lizarb.rbs} +1 -1
- data/tmp/.gitkeep +0 -0
- data/web_files/favicon.ico +0 -0
- data/web_files/favicon.svg +948 -0
- metadata +226 -13
- data/viral.gemspec +0 -45
data/lib/liza/unit.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
module Liza
|
2
|
+
class Unit
|
3
|
+
|
4
|
+
# PARTS
|
5
|
+
|
6
|
+
def self.part key, system: nil
|
7
|
+
App.connect_part self, key, system
|
8
|
+
end
|
9
|
+
|
10
|
+
# SETTINGS
|
11
|
+
|
12
|
+
def self.settings
|
13
|
+
@settings ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get key
|
17
|
+
return settings[key] if settings.has_key? key
|
18
|
+
|
19
|
+
found = nil
|
20
|
+
|
21
|
+
for klass in ancestors
|
22
|
+
break unless klass.respond_to? :settings
|
23
|
+
|
24
|
+
if klass.settings.has_key? key
|
25
|
+
found = klass.settings[key]
|
26
|
+
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
found = settings[key] = found.dup if found.is_a? Enumerable
|
32
|
+
|
33
|
+
found
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.set key, value
|
37
|
+
settings[key] = value
|
38
|
+
value
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.add list, key = nil, value
|
42
|
+
if key
|
43
|
+
fetch(list) { Hash.new }[key] = value
|
44
|
+
else
|
45
|
+
fetch(list) { Set.new } << value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.fetch key, &block
|
50
|
+
x = get key
|
51
|
+
x ||= set key, instance_eval(&block)
|
52
|
+
x
|
53
|
+
end
|
54
|
+
|
55
|
+
def settings
|
56
|
+
@settings ||= {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def get key
|
60
|
+
return settings[key] if settings.has_key? key
|
61
|
+
|
62
|
+
self.class.get key
|
63
|
+
end
|
64
|
+
|
65
|
+
def set key, value
|
66
|
+
settings[key] = value
|
67
|
+
end
|
68
|
+
|
69
|
+
def add list, key = nil, value
|
70
|
+
if key
|
71
|
+
fetch(list) { Hash.new }[key] = value
|
72
|
+
else
|
73
|
+
fetch(list) { Set.new } << value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def fetch key, &block
|
78
|
+
x = get key
|
79
|
+
x ||= set key, eval(&block)
|
80
|
+
x
|
81
|
+
end
|
82
|
+
|
83
|
+
# LOG
|
84
|
+
|
85
|
+
LOG_LEVELS = {
|
86
|
+
:higher => 2,
|
87
|
+
:high => 1,
|
88
|
+
:normal => 0,
|
89
|
+
:low => -1,
|
90
|
+
:lower => -2,
|
91
|
+
}
|
92
|
+
|
93
|
+
set :log_level, :normal
|
94
|
+
set :log_color, :white
|
95
|
+
|
96
|
+
#
|
97
|
+
|
98
|
+
LOG_JUST = 40
|
99
|
+
|
100
|
+
def self.log log_level = :normal, string
|
101
|
+
raise "invalid log_level `#{log_level}`" unless LOG_LEVELS.keys.include? log_level
|
102
|
+
return unless log_level? log_level
|
103
|
+
|
104
|
+
source = (self.is_a? Class) ? self : self.class
|
105
|
+
source = source.to_s.ljust(LOG_JUST).bold.colorize(source.log_color)
|
106
|
+
|
107
|
+
string = "#{source} #{string}"
|
108
|
+
|
109
|
+
DevBox.logs.call string
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.log_level
|
113
|
+
get(:log_level) || :normal
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.log_level? log_level = :normal
|
117
|
+
# TODO
|
118
|
+
true
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.log_color
|
122
|
+
(get(:system) || self).get :log_color
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.log?(log_level = :normal)= log_level? log_level
|
126
|
+
def log(...)= self.class.log(...)
|
127
|
+
def log_level(...)= self.class.log_level(...)
|
128
|
+
def log?(...)= self.class.log?(...)
|
129
|
+
def log_level?(...)= self.class.log_level?(...)
|
130
|
+
def log_color(...)= self.class.log_color(...)
|
131
|
+
|
132
|
+
# SYSTEM
|
133
|
+
|
134
|
+
def self.inherited_explicitly_sets_system
|
135
|
+
|
136
|
+
def self.inherited sub
|
137
|
+
super
|
138
|
+
|
139
|
+
return unless sub.name.to_s.include? "::"
|
140
|
+
|
141
|
+
system = Object.const_get sub.first_namespace
|
142
|
+
|
143
|
+
sub.set :system, system
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Liza
|
2
|
+
class UnitTest < Test
|
3
|
+
test :subject_class do
|
4
|
+
assert subject_class == Liza::Unit
|
5
|
+
end
|
6
|
+
|
7
|
+
test :settings do
|
8
|
+
assert subject_class.get(:log_level) == :normal
|
9
|
+
assert subject_class.get(:log_color) == :white
|
10
|
+
assert subject_class.log_level == :normal
|
11
|
+
assert subject_class.log_color == :white
|
12
|
+
|
13
|
+
assert subject_class.settings == {log_level: :normal, log_color: :white}
|
14
|
+
end
|
15
|
+
|
16
|
+
test :settings_inheritance do
|
17
|
+
class_a = Class.new(subject_class) do
|
18
|
+
set :number, 1
|
19
|
+
|
20
|
+
add :default, 10
|
21
|
+
add :default, 20
|
22
|
+
|
23
|
+
set :array, []
|
24
|
+
add :array, 10
|
25
|
+
add :array, 20
|
26
|
+
|
27
|
+
add :hash, :a, 10
|
28
|
+
add :hash, :b, 20
|
29
|
+
end
|
30
|
+
|
31
|
+
assert class_a.settings == {
|
32
|
+
number: 1,
|
33
|
+
default: Set[10, 20],
|
34
|
+
array: [10, 20],
|
35
|
+
hash: {a: 10, b: 20}
|
36
|
+
}
|
37
|
+
|
38
|
+
assert class_a.get(:default) == Set[10, 20]
|
39
|
+
assert class_a.get(:array) == [10, 20]
|
40
|
+
assert class_a.get(:hash) == {a: 10, b: 20}
|
41
|
+
|
42
|
+
class_b = Class.new(class_a) do
|
43
|
+
set :string, "a"
|
44
|
+
|
45
|
+
add :default, 30
|
46
|
+
add :default, 40
|
47
|
+
|
48
|
+
add :array, 30
|
49
|
+
add :array, 40
|
50
|
+
|
51
|
+
add :hash, :c, 30
|
52
|
+
add :hash, :d, 40
|
53
|
+
end
|
54
|
+
|
55
|
+
assert class_a.settings == {
|
56
|
+
number: 1,
|
57
|
+
default: Set[10, 20],
|
58
|
+
array: [10, 20],
|
59
|
+
hash: {a: 10, b: 20}
|
60
|
+
}
|
61
|
+
|
62
|
+
assert class_a.get(:default) == Set[10, 20]
|
63
|
+
assert class_a.get(:array) == [10, 20]
|
64
|
+
assert class_a.get(:hash) == {a: 10, b: 20}
|
65
|
+
|
66
|
+
assert class_b.settings == {
|
67
|
+
string: "a",
|
68
|
+
default: Set[10, 20, 30, 40],
|
69
|
+
array: [10, 20, 30, 40],
|
70
|
+
hash: {a: 10, b: 20, c: 30, d: 40}
|
71
|
+
}
|
72
|
+
|
73
|
+
assert class_b.get(:default) == Set[10, 20, 30, 40]
|
74
|
+
assert class_b.get(:array) == [10, 20, 30, 40]
|
75
|
+
assert class_b.get(:hash) == {a: 10, b: 20, c: 30, d: 40}
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
data/lib/liza.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Liza
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
#
|
7
|
+
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def log s
|
11
|
+
puts s.bold
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
|
16
|
+
# Checks Object, each system, then Liza for Liza::Unit classes
|
17
|
+
def const name
|
18
|
+
name = name.to_s.camelize.to_sym
|
19
|
+
|
20
|
+
k = const_check_object name
|
21
|
+
return k if k
|
22
|
+
|
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
|
30
|
+
end
|
31
|
+
|
32
|
+
# Checks each system, then Liza for Liza::Unit classes
|
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
|
49
|
+
for k in App.systems.values.reverse
|
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
|
53
|
+
end
|
54
|
+
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def is_unit? kk
|
59
|
+
kk && kk < Liza::Unit
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Class
|
4
|
+
public :eval
|
5
|
+
|
6
|
+
def descendants
|
7
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
8
|
+
end
|
9
|
+
|
10
|
+
def first_namespace
|
11
|
+
name.rpartition('::')[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_namespace
|
15
|
+
name.rpartition('::')[-1]
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
alias lpartition partition
|
5
|
+
|
6
|
+
def camelize
|
7
|
+
split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
|
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
|
25
|
+
end
|
data/lib/lizarb.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "colorize"
|
4
|
+
require "pathname"
|
5
|
+
require "zeitwerk"
|
6
|
+
|
7
|
+
require_relative "lizarb/version"
|
8
|
+
|
9
|
+
module Lizarb
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
#
|
13
|
+
|
14
|
+
GEM_DIR = Gem::Specification.find_by_name("lizarb").gem_dir
|
15
|
+
CUR_DIR = Dir.pwd
|
16
|
+
|
17
|
+
IS_APP_DIR = File.file? "#{CUR_DIR}/app.rb"
|
18
|
+
IS_LIZ_DIR = File.file? "#{CUR_DIR}/lib/lizarb.rb"
|
19
|
+
|
20
|
+
APP_DIR = IS_APP_DIR ? CUR_DIR : GEM_DIR
|
21
|
+
|
22
|
+
#
|
23
|
+
|
24
|
+
module_function
|
25
|
+
|
26
|
+
def log s
|
27
|
+
puts s.bold
|
28
|
+
end
|
29
|
+
|
30
|
+
# called from exe/lizarb
|
31
|
+
def call
|
32
|
+
require "app"
|
33
|
+
|
34
|
+
setup_core_ext
|
35
|
+
setup_gemfile
|
36
|
+
|
37
|
+
require "#{APP_DIR}/app"
|
38
|
+
|
39
|
+
VERSION
|
40
|
+
end
|
41
|
+
|
42
|
+
# called from "#{APP_DIR}/app"
|
43
|
+
def bundle
|
44
|
+
require "bundler/setup"
|
45
|
+
Bundler.require :default
|
46
|
+
|
47
|
+
bundle_liza
|
48
|
+
|
49
|
+
check_mode!
|
50
|
+
end
|
51
|
+
|
52
|
+
# setup
|
53
|
+
|
54
|
+
def setup_core_ext
|
55
|
+
pattern =
|
56
|
+
IS_LIZ_DIR ? "lib/lizarb/ruby/*.rb"
|
57
|
+
: "#{GEM_DIR}/lib/lizarb/ruby/*.rb"
|
58
|
+
|
59
|
+
Dir[pattern].each &method(:load)
|
60
|
+
end
|
61
|
+
|
62
|
+
def setup_gemfile
|
63
|
+
ENV["BUNDLE_GEMFILE"] =
|
64
|
+
IS_APP_DIR ? "#{CUR_DIR}/Gemfile"
|
65
|
+
: "#{GEM_DIR}/exe/Gemfile"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class NetCommand < Liza::Command
|
3
|
+
|
4
|
+
def self.call args
|
5
|
+
log :higher, "Called #{self} with args #{args}"
|
6
|
+
|
7
|
+
ruby_time = Time.now
|
8
|
+
redis_time = ::NetBox.databases.redis.now
|
9
|
+
sqlite_time = ::NetBox.databases.sqlite.now
|
10
|
+
# redis_time = ::RedisDb.current.now
|
11
|
+
# sqlite_time = ::SqliteDb.current.now
|
12
|
+
|
13
|
+
puts <<-OUTPUT.bold
|
14
|
+
|
15
|
+
Time for Ruby: #{ruby_time.to_s.light_red}
|
16
|
+
Time for Redis: #{redis_time.to_s.light_red}
|
17
|
+
Time for Sqlite: #{sqlite_time.to_s.light_red}
|
18
|
+
|
19
|
+
OUTPUT
|
20
|
+
Liza::DevCommand.call []
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class RedisClient < Client
|
3
|
+
|
4
|
+
# https://redis.io/
|
5
|
+
# https://github.com/redis/redis-rb
|
6
|
+
def initialize *args
|
7
|
+
args = [url: Liza.const(:net_box).clients.get(:redis_url)] if args.empty?
|
8
|
+
log "Connecting to #{args}"
|
9
|
+
@conn = Redis.new *args
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :conn
|
13
|
+
|
14
|
+
def call cmd_name, *args
|
15
|
+
t = Time.now
|
16
|
+
result = @conn.send cmd_name, *args
|
17
|
+
|
18
|
+
result
|
19
|
+
ensure
|
20
|
+
log "#{t.diff}s | #{cmd_name} | #{args}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def now
|
24
|
+
call :time
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class RedisClientTest < ClientTest
|
3
|
+
|
4
|
+
def subject
|
5
|
+
@subject ||= subject_class.new
|
6
|
+
end
|
7
|
+
|
8
|
+
test :subject_class do
|
9
|
+
assert subject_class == Liza::RedisClient
|
10
|
+
end
|
11
|
+
|
12
|
+
test :subject do
|
13
|
+
assert subject.conn.class == Redis
|
14
|
+
end
|
15
|
+
|
16
|
+
test :call do
|
17
|
+
result = subject.call :keys
|
18
|
+
assert result.class == Array
|
19
|
+
assert result.count == 0
|
20
|
+
end
|
21
|
+
|
22
|
+
test :now do
|
23
|
+
result = subject.now
|
24
|
+
assert result.class == Array
|
25
|
+
assert result.map(&:class) == [Integer, Integer]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class SqliteClient < Client
|
3
|
+
|
4
|
+
# https://www.sqlite.org/
|
5
|
+
# https://github.com/sparklemotion/sqlite3-ruby
|
6
|
+
def initialize *args
|
7
|
+
args = [Liza.const(:net_box).clients.get(:sqlite)] if args.empty?
|
8
|
+
log "Connecting to #{args}"
|
9
|
+
@conn = SQLite3::Database.new *args
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :conn
|
13
|
+
|
14
|
+
def call sql, *args
|
15
|
+
t = Time.now
|
16
|
+
result = @conn.execute2 sql, *args
|
17
|
+
|
18
|
+
result
|
19
|
+
ensure
|
20
|
+
log "#{t.diff}s | #{sql} | #{args}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def now
|
24
|
+
call "SELECT strftime('%Y-%m-%dT%H:%M:%S.%f', 'now', 'localtime');"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class SqliteClientTest < ClientTest
|
3
|
+
|
4
|
+
def subject
|
5
|
+
@subject ||= subject_class.new ":memory:"
|
6
|
+
end
|
7
|
+
|
8
|
+
test :subject_class do
|
9
|
+
assert subject_class == Liza::SqliteClient
|
10
|
+
end
|
11
|
+
|
12
|
+
test :subject do
|
13
|
+
assert subject.conn.class == SQLite3::Database
|
14
|
+
end
|
15
|
+
|
16
|
+
test :call do
|
17
|
+
result = subject.call "SELECT name, sql FROM sqlite_master WHERE type = 'table';"
|
18
|
+
assert result == [["name", "sql"]]
|
19
|
+
end
|
20
|
+
|
21
|
+
test :now do
|
22
|
+
result = subject.now
|
23
|
+
assert result.class == Array
|
24
|
+
assert result[0] == ["strftime('%Y-%m-%dT%H:%M:%S.%f', 'now', 'localtime')"]
|
25
|
+
assert result[1][0].class == String
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class ClientTest < Liza::ControllerTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == NetSystem::Client
|
6
|
+
end
|
7
|
+
|
8
|
+
test :settings do
|
9
|
+
assert subject_class.log_level == :normal
|
10
|
+
assert subject_class.log_color == :red
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class RedisDbTest < DatabaseTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == NetSystem::RedisDb
|
6
|
+
end
|
7
|
+
|
8
|
+
test :subject do
|
9
|
+
assert subject.client.class == NetSystem::RedisClient
|
10
|
+
end
|
11
|
+
|
12
|
+
test :now do
|
13
|
+
t = subject.now
|
14
|
+
assert! t.is_a? Time
|
15
|
+
assert t.yday == Time.now.yday
|
16
|
+
end
|
17
|
+
|
18
|
+
# test :call do
|
19
|
+
# todo "write this"
|
20
|
+
# end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class NetSystem
|
2
|
+
class SqliteDbTest < DatabaseTest
|
3
|
+
|
4
|
+
test :subject_class do
|
5
|
+
assert subject_class == NetSystem::SqliteDb
|
6
|
+
end
|
7
|
+
|
8
|
+
test :subject do
|
9
|
+
assert subject.client.class == NetSystem::SqliteClient
|
10
|
+
end
|
11
|
+
|
12
|
+
test :now do
|
13
|
+
t = subject.now
|
14
|
+
assert! t.is_a? Time
|
15
|
+
assert t.yday == Time.now.yday
|
16
|
+
end
|
17
|
+
|
18
|
+
# test :call do
|
19
|
+
# todo "write this"
|
20
|
+
# end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|