arql 0.3.21 → 0.3.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/arql.gemspec +1 -1
- data/lib/arql/definition.rb +9 -4
- data/lib/arql/ext/array.rb +17 -6
- data/lib/arql/ext/hash.rb +1 -1
- data/lib/arql/ext/kernel.rb +4 -0
- data/lib/arql/ext/string.rb +40 -0
- data/lib/arql/ext.rb +1 -0
- data/lib/arql/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d592feafd8e37ec93635f7b469d7e14ca614947f2e2f0c73bf5f60be53c74d51
|
4
|
+
data.tar.gz: 176160f368227b27ff5404255c92b9deb6e156f0c96f0d39c19d7a58b521dd3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1058b41bdcacaa7a49c2be9f4150f8193b99108852b4f60d1db27ccac7be8929b3bc35f39b7f15ae97b6de8f4c38d9186927434a945deb7ca336bab151d00a56
|
7
|
+
data.tar.gz: eaedb70ebade65d3c869df89ee8b7a9823f65f26e5becf7af9a546660b22d0d29bf5c51522076560983e79f1cfb4c9e612d3c4a7c4aef4d7ac925a47d28af33c
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arql (0.3.
|
4
|
+
arql (0.3.23)
|
5
5
|
activerecord (>= 6.1.5, < 7.1.0)
|
6
6
|
activesupport (>= 6.1.5, < 7.1.0)
|
7
7
|
caxlsx (~> 3.3.0)
|
@@ -11,7 +11,7 @@ PATH
|
|
11
11
|
net-ssh-gateway (~> 2.0.0)
|
12
12
|
pry (~> 0.14.1)
|
13
13
|
pry-byebug (~> 3.10.1)
|
14
|
-
pry-doc (>= 1.
|
14
|
+
pry-doc (>= 1.4.0)
|
15
15
|
rainbow (~> 3.0.0)
|
16
16
|
ransack (>= 3.2.1)
|
17
17
|
roo (~> 2.9.0)
|
@@ -67,7 +67,7 @@ GEM
|
|
67
67
|
pry-byebug (3.10.1)
|
68
68
|
byebug (~> 11.0)
|
69
69
|
pry (>= 0.13, < 0.15)
|
70
|
-
pry-doc (1.
|
70
|
+
pry-doc (1.4.0)
|
71
71
|
pry (~> 0.11)
|
72
72
|
yard (~> 0.9.11)
|
73
73
|
racc (1.6.2)
|
data/arql.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_dependency 'net-ssh-gateway', '~> 2.0.0'
|
36
36
|
spec.add_dependency 'pry', '~> 0.14.1'
|
37
37
|
spec.add_dependency 'pry-byebug', '~> 3.10.1'
|
38
|
-
spec.add_dependency 'pry-doc', '>= 1.
|
38
|
+
spec.add_dependency 'pry-doc', '>= 1.4.0'
|
39
39
|
spec.add_dependency 'rainbow', '~> 3.0.0'
|
40
40
|
spec.add_dependency 'terminal-table', '~> 1.8.0'
|
41
41
|
spec.add_dependency 'table_print', '~> 1.5.6'
|
data/lib/arql/definition.rb
CHANGED
@@ -5,9 +5,9 @@ module Arql
|
|
5
5
|
module Extension
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
def t
|
8
|
+
def t(**options)
|
9
9
|
puts Terminal::Table.new { |t|
|
10
|
-
v.each { |row| t << (row || :separator) }
|
10
|
+
v(**options).each { |row| t << (row || :separator) }
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
@@ -20,12 +20,17 @@ module Arql
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def v
|
23
|
+
def v(**options)
|
24
24
|
t = []
|
25
25
|
t << ['Attribute Name', 'Attribute Value', 'SQL Type', 'Comment']
|
26
26
|
t << nil
|
27
|
+
compact_mode = options[:compact] || false
|
27
28
|
self.class.connection.columns(self.class.table_name).each do |column|
|
28
|
-
|
29
|
+
value = read_attribute(column.name)
|
30
|
+
if compact_mode && value.blank?
|
31
|
+
next
|
32
|
+
end
|
33
|
+
t << [column.name, value, column.sql_type, column.comment || '']
|
29
34
|
end
|
30
35
|
t
|
31
36
|
end
|
data/lib/arql/ext/array.rb
CHANGED
@@ -27,6 +27,9 @@ class Array
|
|
27
27
|
attrs -= [options[:except]].flatten
|
28
28
|
end
|
29
29
|
end
|
30
|
+
# if options[:compact]
|
31
|
+
# attrs = attrs.select { |e| any { |r| r.attributes[e.to_s]&.present? } }
|
32
|
+
# end
|
30
33
|
puts Terminal::Table.new { |t|
|
31
34
|
t << attrs
|
32
35
|
t << :separator
|
@@ -36,7 +39,7 @@ class Array
|
|
36
39
|
}
|
37
40
|
else
|
38
41
|
table = Terminal::Table.new { |t|
|
39
|
-
v.each { |row| t << (row || :separator)}
|
42
|
+
v(**options).each { |row| t << (row || :separator)}
|
40
43
|
}.to_s
|
41
44
|
|
42
45
|
terminal_width = `tput cols`.to_i
|
@@ -77,23 +80,31 @@ class Array
|
|
77
80
|
nil
|
78
81
|
end
|
79
82
|
|
80
|
-
def v
|
83
|
+
def v(**options)
|
81
84
|
return self unless present?
|
82
85
|
t = []
|
83
86
|
if map(&:class).uniq.size == 1
|
84
87
|
if first.is_a?(ActiveRecord::Base)
|
85
|
-
|
88
|
+
attribute_names = first.attribute_names
|
89
|
+
if options[:compact]
|
90
|
+
attribute_names = attribute_names.select { |e| any? { |r| r.attributes[e]&.present? } }
|
91
|
+
end
|
92
|
+
t << attribute_names
|
86
93
|
t << nil
|
87
94
|
each do |e|
|
88
|
-
t << e.attributes.values_at(*
|
95
|
+
t << e.attributes.values_at(*attribute_names).map(&:as_json)
|
89
96
|
end
|
90
97
|
elsif first.is_a?(Array)
|
91
98
|
t = map { |a| a.map(&:as_json) }
|
92
99
|
elsif first.is_a?(Hash) || first.is_a?(ActiveSupport::HashWithIndifferentAccess)
|
93
|
-
|
100
|
+
keys = first.keys
|
101
|
+
if options[:compact]
|
102
|
+
keys = keys.select { |e| any? { |r| r[e]&.present? } }
|
103
|
+
end
|
104
|
+
t << keys
|
94
105
|
t << nil
|
95
106
|
each do |e|
|
96
|
-
t << e.values_at(*
|
107
|
+
t << e.values_at(*keys).map(&:as_json)
|
97
108
|
end
|
98
109
|
else
|
99
110
|
return self
|
data/lib/arql/ext/hash.rb
CHANGED
@@ -12,7 +12,7 @@ class Hash
|
|
12
12
|
end
|
13
13
|
|
14
14
|
if sheet_data.is_a?(Array)
|
15
|
-
if sheet_data.size > 0 && sheet_data.first.is_a?(
|
15
|
+
if sheet_data.size > 0 && sheet_data.first.is_a?(ActiveRecord::Base)
|
16
16
|
fields = sheet_data.first.attributes.keys
|
17
17
|
sheet.add_row(fields, types: [:string] * fields.size)
|
18
18
|
sheet_data.each do |row|
|
data/lib/arql/ext/kernel.rb
CHANGED
data/lib/arql/ext/string.rb
CHANGED
@@ -10,4 +10,44 @@ class String
|
|
10
10
|
def f
|
11
11
|
expa
|
12
12
|
end
|
13
|
+
|
14
|
+
def parse_excel
|
15
|
+
if File.file?(File.expand_path(self))
|
16
|
+
Kernel.parse_excel(File.expand_path(self))
|
17
|
+
else
|
18
|
+
raise "File not found: #{self}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_csv
|
23
|
+
if File.file?(File.expand_path(self))
|
24
|
+
Kernel.parse_csv(File.expand_path(self))
|
25
|
+
else
|
26
|
+
raise "File not found: #{self}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_json
|
31
|
+
if File.file?(File.expand_path(self))
|
32
|
+
Kernel.parse_json(File.expand_path(self))
|
33
|
+
else
|
34
|
+
raise "File not found: #{self}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse
|
39
|
+
if File.file?(File.expand_path(self))
|
40
|
+
if self =~ /\.xlsx?$/i
|
41
|
+
parse_excel
|
42
|
+
elsif self =~ /\.csv$/i
|
43
|
+
parse_csv
|
44
|
+
elsif self =~ /\.json$/i
|
45
|
+
parse_json
|
46
|
+
else
|
47
|
+
raise "File type not supported: #{self}"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise "File not found: #{self}"
|
51
|
+
end
|
52
|
+
end
|
13
53
|
end
|
data/lib/arql/ext.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Liu Xiang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|
@@ -154,14 +154,14 @@ dependencies:
|
|
154
154
|
requirements:
|
155
155
|
- - ">="
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version: 1.
|
157
|
+
version: 1.4.0
|
158
158
|
type: :runtime
|
159
159
|
prerelease: false
|
160
160
|
version_requirements: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
162
|
- - ">="
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version: 1.
|
164
|
+
version: 1.4.0
|
165
165
|
- !ruby/object:Gem::Dependency
|
166
166
|
name: rainbow
|
167
167
|
requirement: !ruby/object:Gem::Requirement
|