arql 0.2.2 → 0.2.7
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/commands/models.rb +10 -6
- data/lib/arql/definition.rb +29 -14
- data/lib/arql/ext/array.rb +12 -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: 44604f0630f7b6308b9c53bf90b46bd9138b52fdec169baf46bf4e790adfc82b
|
4
|
+
data.tar.gz: 7efecc0c754d4f16eb31a19756de3d95a06d8d93440e480726d6df574827af13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d795bedb12d2bf39bbb2b5e394373b545e35a542e00110708915fa57b5ca2248f5ed64ee975283d0a3a23e3e4ed201a560fc3ba78dac4085650d6eef486c7fdf
|
7
|
+
data.tar.gz: 07c6aacfcd46fe3361ebbf977c553c32aad792cb7cd40ebdb9803f0cb76b32ace4bb4326808dd4db2c61be2f6e3e98ec1ee85753ced7e73ee85f8d1f6ffaf10d
|
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.7)
|
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/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
|
@@ -106,16 +107,22 @@ module Arql
|
|
106
107
|
end
|
107
108
|
end.tap do |clazz|
|
108
109
|
Object.const_set(const_name, clazz).tap do |const|
|
109
|
-
const_name.gsub(/[a-z]*/, '').tap do |
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
const_name.gsub(/[a-z]*/, '').tap do |bare_abbr|
|
111
|
+
abbr_const = nil
|
112
|
+
9.times do |idx|
|
113
|
+
abbr = idx.zero? ? bare_abbr : "#{bare_abbr}#{idx+1}"
|
114
|
+
unless Object.const_defined?(abbr)
|
115
|
+
Object.const_set abbr, const
|
116
|
+
abbr_const = abbr
|
117
|
+
break
|
118
|
+
end
|
113
119
|
end
|
114
120
|
|
115
121
|
@@models << {
|
116
122
|
model: const,
|
117
123
|
abbr: abbr_const,
|
118
|
-
table: table_name
|
124
|
+
table: table_name,
|
125
|
+
comment: table_comment
|
119
126
|
}
|
120
127
|
end
|
121
128
|
end
|
@@ -133,12 +140,14 @@ module Arql
|
|
133
140
|
@@options = options
|
134
141
|
@@models = []
|
135
142
|
ActiveRecord::Base.connection.tap do |conn|
|
143
|
+
Object.const_set('ArqlModel', Class.new(ActiveRecord::Base) { self.abstract_class = true })
|
136
144
|
conn.tables.each do |table_name|
|
145
|
+
table_comment = conn.table_comment(table_name)
|
137
146
|
conn.primary_key(table_name).tap do |pkey|
|
138
147
|
table_name.camelize.tap do |const_name|
|
139
148
|
const_name = 'Modul' if const_name == 'Module'
|
140
149
|
const_name = 'Clazz' if const_name == 'Class'
|
141
|
-
Class.new(
|
150
|
+
Class.new(::ArqlModel) do
|
142
151
|
include Arql::Extension
|
143
152
|
self.primary_key = pkey
|
144
153
|
self.table_name = table_name
|
@@ -157,16 +166,22 @@ module Arql
|
|
157
166
|
end
|
158
167
|
end.tap do |clazz|
|
159
168
|
Object.const_set(const_name, clazz).tap do |const|
|
160
|
-
const_name.gsub(/[a-z]*/, '').tap do |
|
161
|
-
|
162
|
-
|
163
|
-
|
169
|
+
const_name.gsub(/[a-z]*/, '').tap do |bare_abbr|
|
170
|
+
abbr_const = nil
|
171
|
+
9.times do |idx|
|
172
|
+
abbr = idx.zero? ? bare_abbr : "#{bare_abbr}#{idx+1}"
|
173
|
+
unless Object.const_defined?(abbr)
|
174
|
+
Object.const_set abbr, const
|
175
|
+
abbr_const = abbr
|
176
|
+
break
|
177
|
+
end
|
164
178
|
end
|
165
179
|
|
166
180
|
@@models << {
|
167
181
|
model: const,
|
168
182
|
abbr: abbr_const,
|
169
|
-
table: table_name
|
183
|
+
table: table_name,
|
184
|
+
comment: table_comment
|
170
185
|
}
|
171
186
|
end
|
172
187
|
end
|
@@ -178,8 +193,8 @@ module Arql
|
|
178
193
|
end
|
179
194
|
|
180
195
|
::ActiveRecord::Relation.class_eval do
|
181
|
-
def t(*attrs)
|
182
|
-
records.t(*attrs)
|
196
|
+
def t(*attrs, **options)
|
197
|
+
records.t(*attrs, **options)
|
183
198
|
end
|
184
199
|
|
185
200
|
def v
|
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/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.7
|
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
|