tallty_import_export 1.0.14 → 1.0.19

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: afdaeaa5f7a0eab21b85fdd7aafa0677afba151a2564fd0fdd1a9916132af0f2
4
- data.tar.gz: ae51318bbda8fe1c37533ad29c34a64c9c5d52e2a3b9e7bcb491c8cee1039cd2
3
+ metadata.gz: 47d4e395eb95191fc74c60002ce97284ba86d11b0d7708be87e59f13296ac983
4
+ data.tar.gz: 78935b1942529ec78a9ed6b7430d4fa79fe8307f1ecb4f77cffb295c95a5a1cb
5
5
  SHA512:
6
- metadata.gz: b6966aa85b471dd960fa05ae537c4f1b6938efe30635d0261ec5763e66bd83cf8de5252831ddb46fdb248eeac3c622df52594f88738e8312a958b2bf734891d3
7
- data.tar.gz: 252f71c459a9b1034a32b75421474671df4568145c0f33f19cbdb6f83fb42ee7f210e9dcff83a7ee65fdea42db11b52d03a3df8f287e3ede74bb25f231ee56be
6
+ metadata.gz: 5a59cfce4a219cf9c8022d7b9d6dcc527e1d8fd72a47b8a6536afdc79e792ddfe6e2161bcfdd480d388adf54345447b3ab70e2e8f6db217c2f6e8ddaaedb010e
7
+ data.tar.gz: 55b49d0a89e8194d1c5029fc2398b9851b079e215acef761a7e37f8c158dc2282740c5025bb43f5abacacbfec7872b0980e53510cd23d479e5967baffd313279
@@ -40,11 +40,13 @@ module TalltyImportExport
40
40
  if @group_by.present?
41
41
  if records.is_a?(Array)
42
42
  records.group_by { |record| record.send(@group_by)}.each do |key, group_records|
43
+ next unless key.present?
43
44
  @group_key = key
44
45
  export_workbook workbook, group_records
45
46
  end
46
47
  else
47
48
  records.group(@group_by).count.keys.each do |key|
49
+ next unless key.present?
48
50
  @group_key = key
49
51
  export_workbook workbook, records.ransack("#{@group_where}" => key).result
50
52
  end
@@ -15,6 +15,7 @@ module TalltyImportExport
15
15
  # convert: 导入时候,把excel的内容转换成导入时候代码逻辑需要的内容
16
16
  # primary_key: 是否是主键
17
17
  # json: model_payload,代表存储在某一个列中
18
+ # finder: 执行代码,可以查找到相关的对象
18
19
 
19
20
  # xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
20
21
  def import_xlsx xlsx_file, associations, **options
@@ -53,6 +54,7 @@ module TalltyImportExport
53
54
  options = options.with_indifferent_access
54
55
  @headers = options.delete(:headers) || import_headers
55
56
  @primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
57
+ @params = options
56
58
 
57
59
  @excel_hash = @headers.reduce({}) do |h, header|
58
60
  h[header[:key].to_sym] = header[:name]
@@ -63,6 +65,8 @@ module TalltyImportExport
63
65
  end
64
66
 
65
67
  def process_line_info line_info, associations
68
+ # 去除空行内容
69
+ return unless line_info.values.any?(&:present?)
66
70
  # 转换处理导入的数据格式
67
71
  line_info = convert_data(line_info)
68
72
 
@@ -84,6 +88,9 @@ module TalltyImportExport
84
88
  if header[:json]
85
89
  h[header[:json]] ||= {}
86
90
  h[header[:json]][k] = val
91
+ elsif header[:finder]
92
+ $SAFE = 2
93
+ h[k.to_sym] = eval header[:finder]
87
94
  else
88
95
  h[k.to_sym] = val
89
96
  end
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.14"
2
+ VERSION = "1.0.19"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tallty_import_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.14
4
+ version: 1.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - liyijie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2021-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip