arql 0.2.3 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf94862baf6c8e5ff36589e84a022e892b4b88664ecc300c51d313a541e982fd
4
- data.tar.gz: baa0a4b30e5efeb4083347c18f2863faa764052505e46442e45dd9af519612b0
3
+ metadata.gz: 470deccd5ba138549ecac9e05bb6bb57fee7c6954965443656dc7529344eaf75
4
+ data.tar.gz: a3eb2b9eabb1e36de3b9a31603d754c23f1e7bb70c5fe567274686975636229c
5
5
  SHA512:
6
- metadata.gz: aa3a4aba5288c64c7969efe368713e9f2a64ff9dfde3f41d47b9d8f3ec2f64fbfbe5479d6dc1c95281d82f68497616f44f78e84b635e312b6c6e40528871e6cf
7
- data.tar.gz: cae343a1411c59e683dcc99ee309d1ca91100c2c8cf22cbff37ffe04cc02e338d38562e0623a752c5f0803926fba1b0f5a2332074ec3f98083dadd0b8439ab0e
6
+ metadata.gz: 67e739e75aae86ab98622646b66a0b1f695cae31f673d1d95625e151ee6f14c818c9b230dca823fa3deb7f0b8d2c1c3303c33158d1e2334a85b6eb36ff713e8c
7
+ data.tar.gz: f6fdde5dd75d1a8f17b89713b481e0f54e897b9a6c27a6a049601f82c25fe3dde0c255e870cf177eb11b73d55942908c0b74aed664243376d29737dff85e884d
@@ -1,10 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.2.3)
4
+ arql (0.2.8)
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.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)
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.7)
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.0)
81
+ zeitwerk (2.4.2)
79
82
 
80
83
  PLATFORMS
81
84
  ruby
@@ -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'
@@ -22,6 +22,7 @@ module Arql
22
22
  def initialize(options)
23
23
  require 'active_support/all'
24
24
  require 'active_record'
25
+ require 'composite_primary_keys'
25
26
  require "arql/connection"
26
27
  require "arql/definition"
27
28
  @options = options
@@ -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.each { |row| t << (row || :separator) }
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'
@@ -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 column.name == connection.primary_key(table_name)
28
+ pk = if [connection.primary_key(table_name)].flatten.include?(column.name)
29
29
  'Y'
30
30
  else
31
31
  ''
@@ -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
- Class.new(ActiveRecord::Base) do
91
+ Class.new(::ArqlModel) do
91
92
  include Arql::Extension
92
- self.primary_key = pkey
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 |abbr|
110
- unless Object.const_defined?(abbr)
111
- Object.const_set abbr, const
112
- abbr_const = abbr
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
@@ -133,14 +144,20 @@ module Arql
133
144
  @@options = options
134
145
  @@models = []
135
146
  ActiveRecord::Base.connection.tap do |conn|
147
+ Object.const_set('ArqlModel', Class.new(ActiveRecord::Base) { self.abstract_class = true })
136
148
  conn.tables.each do |table_name|
149
+ table_comment = conn.table_comment(table_name)
137
150
  conn.primary_key(table_name).tap do |pkey|
138
151
  table_name.camelize.tap do |const_name|
139
152
  const_name = 'Modul' if const_name == 'Module'
140
153
  const_name = 'Clazz' if const_name == 'Class'
141
- Class.new(ActiveRecord::Base) do
154
+ Class.new(::ArqlModel) do
142
155
  include Arql::Extension
143
- self.primary_key = pkey
156
+ if pkey.is_a?(Array)
157
+ self.primary_keys = pkey
158
+ else
159
+ self.primary_key = pkey
160
+ end
144
161
  self.table_name = table_name
145
162
  self.inheritance_column = nil
146
163
  self.default_timezone = :local
@@ -157,16 +174,22 @@ module Arql
157
174
  end
158
175
  end.tap do |clazz|
159
176
  Object.const_set(const_name, clazz).tap do |const|
160
- const_name.gsub(/[a-z]*/, '').tap do |abbr|
161
- unless Object.const_defined?(abbr)
162
- Object.const_set abbr, const
163
- abbr_const = abbr
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
164
186
  end
165
187
 
166
188
  @@models << {
167
189
  model: const,
168
190
  abbr: abbr_const,
169
- table: table_name
191
+ table: table_name,
192
+ comment: table_comment
170
193
  }
171
194
  end
172
195
  end
@@ -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 = first.attribute_names.map(&:to_sym) if attrs.empty?
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
@@ -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 column.name == ::ActiveRecord::Base.connection.primary_key(table_name)
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 column.name == ::ActiveRecord::Base.connection.primary_key(table_name)
47
+ pk = if [::ActiveRecord::Base.connection.primary_key(table_name)].flatten.include?(column_name)
48
48
  'Y'
49
49
  else
50
50
  ''
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.8"
3
3
  end
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.3
4
+ version: 0.2.8
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-09-24 00:00:00.000000000 Z
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