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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f575a97ddab11ee3b4f5069cfe04877fde773dfc6cb454b44fe216d8e5c9ce77
4
- data.tar.gz: b501edf60d265681e49ad3df6b536b9d2ea566fa666c0daa75b46c9b50945e5c
3
+ metadata.gz: d592feafd8e37ec93635f7b469d7e14ca614947f2e2f0c73bf5f60be53c74d51
4
+ data.tar.gz: 176160f368227b27ff5404255c92b9deb6e156f0c96f0d39c19d7a58b521dd3a
5
5
  SHA512:
6
- metadata.gz: faa91240930fef4f8dca5dce889f1857439fc9e11d756c6a50abc323a21afc42acc6dd208e410fd326a5e7420e9afa3a953509bf435073b15719085e420c3200
7
- data.tar.gz: e2756eedf934bfeaedad1756c270fdc46582cf151c892a9c053de0161cd4336fb252365b75d78f3328446028738ec57c2854443596cc4af9930921439357bb94
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.21)
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.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|
@@ -109,4 +109,8 @@ module Kernel
109
109
  end
110
110
  end
111
111
 
112
+ def parse_json(filename)
113
+ JSON.parse(IO.read(File.expand_path(filename)))
114
+ end
115
+
112
116
  end
@@ -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
@@ -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.23"
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.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: 2022-12-29 00:00:00.000000000 Z
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.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