arql 0.2.4 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -9
- data/arql.gemspec +1 -0
- data/lib/arql/app.rb +1 -0
- data/lib/arql/commands/models.rb +10 -6
- data/lib/arql/commands/table.rb +1 -1
- data/lib/arql/definition.rb +34 -12
- data/lib/arql/ext/array.rb +3 -1
- data/lib/arql/ext/kernel.rb +2 -2
- data/lib/arql/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 547372d219f1903fb2ea57628747977c703cc394ce0b80653c4240268f634da0
|
4
|
+
data.tar.gz: bf3b769511f63c366f97011b52cc6227fe062db18ed82171a071718b9e1ad093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 387959d7154d8aa3893f9fce185b156c12302effd413ba9a3ca40749061c3cf4fa20c8352a8cc68fc0318e86cb3abbd9318ba2befd2ea42710a81aa01d47bc7f
|
7
|
+
data.tar.gz: 309295ae45053888434f888eef6fd46b881024837f8a5bb20a83d31fbf84de34b7fa06e4eada8ee714d1ce6e12f33a2fdb993d6d50f4f804eb13f70aa3f19cf8
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arql (0.2.
|
4
|
+
arql (0.2.9)
|
5
5
|
activerecord (~> 6.0.3)
|
6
6
|
activesupport (~> 6.0.3)
|
7
7
|
caxlsx (~> 3.0.2)
|
8
|
+
composite_primary_keys (~> 12.0.3)
|
8
9
|
mysql2 (~> 0.5.3)
|
9
10
|
net-ssh-gateway (~> 2.0.0)
|
10
11
|
pry (~> 0.13.1)
|
@@ -19,12 +20,12 @@ PATH
|
|
19
20
|
GEM
|
20
21
|
remote: https://rubygems.org/
|
21
22
|
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.
|
23
|
+
activemodel (6.0.3.4)
|
24
|
+
activesupport (= 6.0.3.4)
|
25
|
+
activerecord (6.0.3.4)
|
26
|
+
activemodel (= 6.0.3.4)
|
27
|
+
activesupport (= 6.0.3.4)
|
28
|
+
activesupport (6.0.3.4)
|
28
29
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
30
|
i18n (>= 0.7, < 2)
|
30
31
|
minitest (~> 5.1)
|
@@ -37,6 +38,8 @@ GEM
|
|
37
38
|
nokogiri (~> 1.10, >= 1.10.4)
|
38
39
|
rubyzip (>= 1.3.0, < 3)
|
39
40
|
coderay (1.1.3)
|
41
|
+
composite_primary_keys (12.0.3)
|
42
|
+
activerecord (~> 6.0.0)
|
40
43
|
concurrent-ruby (1.1.7)
|
41
44
|
htmlentities (4.3.4)
|
42
45
|
i18n (1.8.5)
|
@@ -71,11 +74,11 @@ GEM
|
|
71
74
|
terminal-table (1.8.0)
|
72
75
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
73
76
|
thread_safe (0.3.6)
|
74
|
-
tzinfo (1.2.
|
77
|
+
tzinfo (1.2.8)
|
75
78
|
thread_safe (~> 0.1)
|
76
79
|
unicode-display_width (1.7.0)
|
77
80
|
yard (0.9.25)
|
78
|
-
zeitwerk (2.4.
|
81
|
+
zeitwerk (2.4.2)
|
79
82
|
|
80
83
|
PLATFORMS
|
81
84
|
ruby
|
data/arql.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
# spec.add_dependency 'activerecord-sqlserver-adapter'
|
30
30
|
# spec.add_dependency 'activerecord-oracle_enhanced-adapter'
|
31
31
|
spec.add_dependency 'activerecord', '~> 6.0.3'
|
32
|
+
spec.add_dependency 'composite_primary_keys', '~> 12.0.3'
|
32
33
|
spec.add_dependency 'activesupport', '~> 6.0.3'
|
33
34
|
spec.add_dependency 'net-ssh-gateway', '~> 2.0.0'
|
34
35
|
spec.add_dependency 'pry', '~> 0.13.1'
|
data/lib/arql/app.rb
CHANGED
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| e.start_with?('/') ? eval(e) : Regexp.new(e) })
|
27
31
|
end
|
28
32
|
|
29
33
|
Pry.commands.alias_command 'l', 'm'
|
data/lib/arql/commands/table.rb
CHANGED
@@ -25,7 +25,7 @@ module Arql::Commands
|
|
25
25
|
t << nil
|
26
26
|
connection = ::ActiveRecord::Base.connection
|
27
27
|
connection.columns(table_name).each do |column|
|
28
|
-
pk = if
|
28
|
+
pk = if [connection.primary_key(table_name)].flatten.include?(column.name)
|
29
29
|
'Y'
|
30
30
|
else
|
31
31
|
''
|
data/lib/arql/definition.rb
CHANGED
@@ -83,13 +83,18 @@ 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
91
|
Class.new(::ArqlModel) do
|
91
92
|
include Arql::Extension
|
92
|
-
|
93
|
+
if pkey.is_a?(Array)
|
94
|
+
self.primary_keys = pkey
|
95
|
+
else
|
96
|
+
self.primary_key = pkey
|
97
|
+
end
|
93
98
|
self.table_name = table_name
|
94
99
|
self.inheritance_column = nil
|
95
100
|
self.default_timezone = :local
|
@@ -106,16 +111,22 @@ module Arql
|
|
106
111
|
end
|
107
112
|
end.tap do |clazz|
|
108
113
|
Object.const_set(const_name, clazz).tap do |const|
|
109
|
-
const_name.gsub(/[a-z]*/, '').tap do |
|
110
|
-
|
111
|
-
|
112
|
-
|
114
|
+
const_name.gsub(/[a-z]*/, '').tap do |bare_abbr|
|
115
|
+
abbr_const = nil
|
116
|
+
9.times do |idx|
|
117
|
+
abbr = idx.zero? ? bare_abbr : "#{bare_abbr}#{idx+1}"
|
118
|
+
unless Object.const_defined?(abbr)
|
119
|
+
Object.const_set abbr, const
|
120
|
+
abbr_const = abbr
|
121
|
+
break
|
122
|
+
end
|
113
123
|
end
|
114
124
|
|
115
125
|
@@models << {
|
116
126
|
model: const,
|
117
127
|
abbr: abbr_const,
|
118
|
-
table: table_name
|
128
|
+
table: table_name,
|
129
|
+
comment: table_comment
|
119
130
|
}
|
120
131
|
end
|
121
132
|
end
|
@@ -135,13 +146,18 @@ module Arql
|
|
135
146
|
ActiveRecord::Base.connection.tap do |conn|
|
136
147
|
Object.const_set('ArqlModel', Class.new(ActiveRecord::Base) { self.abstract_class = true })
|
137
148
|
conn.tables.each do |table_name|
|
149
|
+
table_comment = conn.table_comment(table_name)
|
138
150
|
conn.primary_key(table_name).tap do |pkey|
|
139
151
|
table_name.camelize.tap do |const_name|
|
140
152
|
const_name = 'Modul' if const_name == 'Module'
|
141
153
|
const_name = 'Clazz' if const_name == 'Class'
|
142
154
|
Class.new(::ArqlModel) do
|
143
155
|
include Arql::Extension
|
144
|
-
|
156
|
+
if pkey.is_a?(Array)
|
157
|
+
self.primary_keys = pkey
|
158
|
+
else
|
159
|
+
self.primary_key = pkey
|
160
|
+
end
|
145
161
|
self.table_name = table_name
|
146
162
|
self.inheritance_column = nil
|
147
163
|
self.default_timezone = :local
|
@@ -158,16 +174,22 @@ module Arql
|
|
158
174
|
end
|
159
175
|
end.tap do |clazz|
|
160
176
|
Object.const_set(const_name, clazz).tap do |const|
|
161
|
-
const_name.gsub(/[a-z]*/, '').tap do |
|
162
|
-
|
163
|
-
|
164
|
-
|
177
|
+
const_name.gsub(/[a-z]*/, '').tap do |bare_abbr|
|
178
|
+
abbr_const = nil
|
179
|
+
9.times do |idx|
|
180
|
+
abbr = idx.zero? ? bare_abbr : "#{bare_abbr}#{idx+1}"
|
181
|
+
unless Object.const_defined?(abbr)
|
182
|
+
Object.const_set abbr, const
|
183
|
+
abbr_const = abbr
|
184
|
+
break
|
185
|
+
end
|
165
186
|
end
|
166
187
|
|
167
188
|
@@models << {
|
168
189
|
model: const,
|
169
190
|
abbr: abbr_const,
|
170
|
-
table: table_name
|
191
|
+
table: table_name,
|
192
|
+
comment: table_comment
|
171
193
|
}
|
172
194
|
end
|
173
195
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -15,8 +15,10 @@ class Array
|
|
15
15
|
|
16
16
|
def t(*attrs, **options)
|
17
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
|
18
20
|
if options.present? && options[:except]
|
19
|
-
attrs =
|
21
|
+
attrs = column_names if attrs.empty?
|
20
22
|
if options[:except].is_a?(Regexp)
|
21
23
|
attrs.reject! { |e| e =~ options[:except] }
|
22
24
|
else
|
data/lib/arql/ext/kernel.rb
CHANGED
@@ -25,7 +25,7 @@ module Kernel
|
|
25
25
|
Terminal::Table.new { |t|
|
26
26
|
t.headings = ['PK', 'Name', 'SQL Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
|
27
27
|
t.rows = table[:columns].map { |column|
|
28
|
-
pk = if
|
28
|
+
pk = if [::ActiveRecord::Base.connection.primary_key(table_name)].flatten.include?(column_name)
|
29
29
|
'Y'
|
30
30
|
else
|
31
31
|
''
|
@@ -44,7 +44,7 @@ module Kernel
|
|
44
44
|
Terminal::Table.new { |t|
|
45
45
|
t.headings = ['PK', 'Name', 'SQL Type', 'Limit', 'Precision', 'Scale', 'Default', 'Nullable', 'Comment']
|
46
46
|
t.rows = table[:columns].map { |column|
|
47
|
-
pk = if
|
47
|
+
pk = if [::ActiveRecord::Base.connection.primary_key(table_name)].flatten.include?(column_name)
|
48
48
|
'Y'
|
49
49
|
else
|
50
50
|
''
|
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.9
|
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-12-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 6.0.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: composite_primary_keys
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 12.0.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 12.0.3
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activesupport
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|