arql 0.3.21 → 0.3.22

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: f575a97ddab11ee3b4f5069cfe04877fde773dfc6cb454b44fe216d8e5c9ce77
4
- data.tar.gz: b501edf60d265681e49ad3df6b536b9d2ea566fa666c0daa75b46c9b50945e5c
3
+ metadata.gz: f4178a1d360f59152ce5fac37b745a98a77ac744090114b6c9d70e89ec4dfe57
4
+ data.tar.gz: 46520be1d1411eb164160d7e42d81012f5147272014556b6825e3cd122ed483c
5
5
  SHA512:
6
- metadata.gz: faa91240930fef4f8dca5dce889f1857439fc9e11d756c6a50abc323a21afc42acc6dd208e410fd326a5e7420e9afa3a953509bf435073b15719085e420c3200
7
- data.tar.gz: e2756eedf934bfeaedad1756c270fdc46582cf151c892a9c053de0161cd4336fb252365b75d78f3328446028738ec57c2854443596cc4af9930921439357bb94
6
+ metadata.gz: 377195d8ebfe1a1a1c5c0eac7d31533171bb95452eee33c2a74048b6d620e565d9ac804d821f1a9201ad803448717e20f50ad7e079065273e866e155535bae99
7
+ data.tar.gz: 3c2a29b255032fc6efc7dc109a557e3e9dc2d8145854fa1d514d9b14551278424b95b81fd6f02d59cfff33a6fa66ae21e1d6cde1a7f408f9ba784189b13d7626
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- arql (0.3.21)
4
+ arql (0.3.22)
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.3.0)
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.3.0)
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.3.0'
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'
@@ -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
- t << [column.name, read_attribute(column.name), column.sql_type, column.comment || '']
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
@@ -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
- t << first.attribute_names
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(*first.attribute_names).map(&:as_json)
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
- t << first.keys
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(*first.keys).map(&:as_json)
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?(ActiveModel::Base)
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.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'arql/ext/object'
2
2
  require 'arql/ext/array'
3
+ require 'arql/ext/hash'
3
4
  require 'arql/ext/time'
4
5
  require 'arql/ext/string'
5
6
  require 'arql/ext/kernel'
data/lib/arql/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arql
2
- VERSION = "0.3.21"
2
+ VERSION = "0.3.22"
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.3.21
4
+ version: 0.3.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liu Xiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2023-04-17 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.3.0
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.3.0
164
+ version: 1.4.0
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: rainbow
167
167
  requirement: !ruby/object:Gem::Requirement