arql 0.2.1 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -8
- data/lib/arql/app.rb +2 -1
- data/lib/arql/commands/models.rb +10 -6
- data/lib/arql/definition.rb +17 -6
- data/lib/arql/ext/array.rb +12 -2
- data/lib/arql/ext/object.rb +4 -0
- data/lib/arql/repl.rb +2 -2
- data/lib/arql/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92f3117b0baa9b0c54cc683a73251094697b5e2fb8ed7cb329f37b43ad0bbe2e
|
4
|
+
data.tar.gz: 2b839cf6ec293f162faa2f29c7d7421679185c4874f1a4c826d13d4be26350a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07790dbd1bbff85f9fee6f86346967ecac0e70c0334255eb7041b475a41b7d569a01f40d0d2f8757de34362dcaaff839e31a27d13865f1f40f533ce409388fc
|
7
|
+
data.tar.gz: a82ae15b63a25e22e7a50e6a1a1dc8173dc5881c5c032851fe69e8639dcfc860d734a557f74dfce38868dac2dd86b2f9e2c94b8e487fa17271967b0eb56d6367
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arql (0.2.
|
4
|
+
arql (0.2.6)
|
5
5
|
activerecord (~> 6.0.3)
|
6
6
|
activesupport (~> 6.0.3)
|
7
7
|
caxlsx (~> 3.0.2)
|
@@ -19,12 +19,12 @@ PATH
|
|
19
19
|
GEM
|
20
20
|
remote: https://rubygems.org/
|
21
21
|
specs:
|
22
|
-
activemodel (6.0.3.
|
23
|
-
activesupport (= 6.0.3.
|
24
|
-
activerecord (6.0.3.
|
25
|
-
activemodel (= 6.0.3.
|
26
|
-
activesupport (= 6.0.3.
|
27
|
-
activesupport (6.0.3.
|
22
|
+
activemodel (6.0.3.3)
|
23
|
+
activesupport (= 6.0.3.3)
|
24
|
+
activerecord (6.0.3.3)
|
25
|
+
activemodel (= 6.0.3.3)
|
26
|
+
activesupport (= 6.0.3.3)
|
27
|
+
activesupport (6.0.3.3)
|
28
28
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
29
|
i18n (>= 0.7, < 2)
|
30
30
|
minitest (~> 5.1)
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
method_source (1.0.0)
|
45
45
|
mimemagic (0.3.5)
|
46
46
|
mini_portile2 (2.4.0)
|
47
|
-
minitest (5.14.
|
47
|
+
minitest (5.14.2)
|
48
48
|
mysql2 (0.5.3)
|
49
49
|
net-ssh (6.1.0)
|
50
50
|
net-ssh-gateway (2.0.0)
|
data/lib/arql/app.rb
CHANGED
@@ -4,7 +4,7 @@ module Arql
|
|
4
4
|
class App
|
5
5
|
|
6
6
|
class << self
|
7
|
-
attr_accessor :log_io, :env, :prompt
|
7
|
+
attr_accessor :log_io, :env, :prompt, :instance
|
8
8
|
|
9
9
|
def config
|
10
10
|
@@effective_config
|
@@ -29,6 +29,7 @@ module Arql
|
|
29
29
|
Connection.open(connect_options)
|
30
30
|
@definition = Definition.new(effective_config)
|
31
31
|
load_initializer!
|
32
|
+
App.instance = self
|
32
33
|
end
|
33
34
|
|
34
35
|
def connect_options
|
data/lib/arql/commands/models.rb
CHANGED
@@ -5,25 +5,29 @@ module Arql::Commands
|
|
5
5
|
class << self
|
6
6
|
def models
|
7
7
|
t = []
|
8
|
-
t << ['Table Name', 'Model Class', 'Abbr']
|
8
|
+
t << ['Table Name', 'Model Class', 'Abbr', 'Comment']
|
9
9
|
t << nil
|
10
10
|
Arql::Definition.models.each do |definition|
|
11
|
-
t << [definition[:table], definition[:model].name, definition[:abbr] || '']
|
11
|
+
t << [definition[:table], definition[:model].name, definition[:abbr] || '', definition[:comment] || '']
|
12
12
|
end
|
13
13
|
t
|
14
14
|
end
|
15
15
|
|
16
|
-
def models_table
|
16
|
+
def models_table(regexp)
|
17
17
|
Terminal::Table.new do |t|
|
18
|
-
models.
|
18
|
+
models.each_with_index { |row, idx| t << (row || :separator) if row.nil? ||
|
19
|
+
regexp.nil? ||
|
20
|
+
idx.zero? ||
|
21
|
+
row.any? { |e| e =~ regexp }
|
22
|
+
}
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
Pry.commands.block_command 'm' do
|
28
|
+
Pry.commands.block_command 'm' do |regexp|
|
25
29
|
puts
|
26
|
-
puts Models::models_table
|
30
|
+
puts Models::models_table(regexp.try { |e| eval(e) })
|
27
31
|
end
|
28
32
|
|
29
33
|
Pry.commands.alias_command 'l', 'm'
|
data/lib/arql/definition.rb
CHANGED
@@ -83,11 +83,12 @@ module Arql
|
|
83
83
|
@@models = []
|
84
84
|
ActiveRecord::Base.connection.tap do |conn|
|
85
85
|
conn.tables.each do |table_name|
|
86
|
+
table_comment = conn.table_comment(table_name)
|
86
87
|
conn.primary_key(table_name).tap do |pkey|
|
87
88
|
table_name.camelize.tap do |const_name|
|
88
89
|
const_name = 'Modul' if const_name == 'Module'
|
89
90
|
const_name = 'Clazz' if const_name == 'Class'
|
90
|
-
Class.new(
|
91
|
+
Class.new(::ArqlModel) do
|
91
92
|
include Arql::Extension
|
92
93
|
self.primary_key = pkey
|
93
94
|
self.table_name = table_name
|
@@ -115,7 +116,8 @@ module Arql
|
|
115
116
|
@@models << {
|
116
117
|
model: const,
|
117
118
|
abbr: abbr_const,
|
118
|
-
table: table_name
|
119
|
+
table: table_name,
|
120
|
+
comment: table_comment
|
119
121
|
}
|
120
122
|
end
|
121
123
|
end
|
@@ -124,6 +126,8 @@ module Arql
|
|
124
126
|
end
|
125
127
|
end
|
126
128
|
end
|
129
|
+
|
130
|
+
App.instance&.load_initializer!
|
127
131
|
end
|
128
132
|
end
|
129
133
|
|
@@ -131,12 +135,14 @@ module Arql
|
|
131
135
|
@@options = options
|
132
136
|
@@models = []
|
133
137
|
ActiveRecord::Base.connection.tap do |conn|
|
138
|
+
Object.const_set('ArqlModel', Class.new(ActiveRecord::Base) { self.abstract_class = true })
|
134
139
|
conn.tables.each do |table_name|
|
140
|
+
table_comment = conn.table_comment(table_name)
|
135
141
|
conn.primary_key(table_name).tap do |pkey|
|
136
142
|
table_name.camelize.tap do |const_name|
|
137
143
|
const_name = 'Modul' if const_name == 'Module'
|
138
144
|
const_name = 'Clazz' if const_name == 'Class'
|
139
|
-
Class.new(
|
145
|
+
Class.new(::ArqlModel) do
|
140
146
|
include Arql::Extension
|
141
147
|
self.primary_key = pkey
|
142
148
|
self.table_name = table_name
|
@@ -164,7 +170,8 @@ module Arql
|
|
164
170
|
@@models << {
|
165
171
|
model: const,
|
166
172
|
abbr: abbr_const,
|
167
|
-
table: table_name
|
173
|
+
table: table_name,
|
174
|
+
comment: table_comment
|
168
175
|
}
|
169
176
|
end
|
170
177
|
end
|
@@ -176,14 +183,18 @@ module Arql
|
|
176
183
|
end
|
177
184
|
|
178
185
|
::ActiveRecord::Relation.class_eval do
|
179
|
-
def t
|
180
|
-
records.t
|
186
|
+
def t(*attrs, **options)
|
187
|
+
records.t(*attrs, **options)
|
181
188
|
end
|
182
189
|
|
183
190
|
def v
|
184
191
|
records.v
|
185
192
|
end
|
186
193
|
|
194
|
+
def a
|
195
|
+
to_a
|
196
|
+
end
|
197
|
+
|
187
198
|
def write_csv(filename, *fields, **options)
|
188
199
|
records.write_csv(filename, *fields, **options)
|
189
200
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -13,8 +13,18 @@ class Array
|
|
13
13
|
end.join("\n")
|
14
14
|
end
|
15
15
|
|
16
|
-
def t(*attrs)
|
17
|
-
if attrs.present? && present? && first.is_a?(ActiveRecord::Base)
|
16
|
+
def t(*attrs, **options)
|
17
|
+
if (attrs.present? || options.present? && options[:except]) && present? && first.is_a?(ActiveRecord::Base)
|
18
|
+
column_names = first.attribute_names.map(&:to_sym)
|
19
|
+
attrs = attrs.flat_map { |e| e.is_a?(Regexp) ? column_names.grep(e) : e }.uniq
|
20
|
+
if options.present? && options[:except]
|
21
|
+
attrs = column_names if attrs.empty?
|
22
|
+
if options[:except].is_a?(Regexp)
|
23
|
+
attrs.reject! { |e| e =~ options[:except] }
|
24
|
+
else
|
25
|
+
attrs -= [options[:except]].flatten
|
26
|
+
end
|
27
|
+
end
|
18
28
|
puts Terminal::Table.new { |t|
|
19
29
|
t << attrs
|
20
30
|
t << :separator
|
data/lib/arql/ext/object.rb
CHANGED
data/lib/arql/repl.rb
CHANGED
@@ -25,7 +25,7 @@ module Arql
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def prompt
|
28
|
-
[proc do |obj, nest_level,
|
28
|
+
[proc do |obj, nest_level, pry_instance|
|
29
29
|
if obj == main_object && nest_level == 0
|
30
30
|
nest_level_prompt = ''
|
31
31
|
else
|
@@ -35,7 +35,7 @@ module Arql
|
|
35
35
|
"(#{obj}:#{nest_level})"
|
36
36
|
end
|
37
37
|
end
|
38
|
-
"%s#{Rainbow('@').green}%s#{nest_level_prompt} %s " % [Rainbow('ARQL').red, Rainbow(App.prompt).yellow, Rainbow('❯').green]
|
38
|
+
"%s#{Rainbow('@').green}%s#{nest_level_prompt} [%d] %s " % [Rainbow('ARQL').red, Rainbow(App.prompt).yellow, pry_instance.input_ring.count, Rainbow('❯').green]
|
39
39
|
end]
|
40
40
|
end
|
41
41
|
end
|
data/lib/arql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|