tallty_import_export 1.0.28 → 1.0.29

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: 7d689c40b8f11354501a465563d14f5ab1060137fb2221180db05c8a18fe2b0d
4
- data.tar.gz: 9cbd15c9a1eae1a0e036dd4557fb5197e3f595067b035dd01119167becee6d3c
3
+ metadata.gz: 0043f0699fb0631c48a0c1dcd018ccad9cdda7dfa376c0a702bf7857338e04a5
4
+ data.tar.gz: 7a8dd851866ea1bc55f87ac8ec443587e6776cfd3c52b8b76fcd9f982aeba513
5
5
  SHA512:
6
- metadata.gz: a11b8561c856588abf871fe6cac330e3a9412e468c6ff2d3480be75b8976b22a7037a655c51df7c884a367d9efa7c8b362c1c46ca3a1e5824f8777ccf0bb1204
7
- data.tar.gz: d178c5d5ae84107a04862e7b5b929ba8546776b1400ed79bde6c518f656d6ac7c573bfaaad3d60b499ec18d1cf9df3a09962d0669c251acbc24f905939ab884e
6
+ metadata.gz: 406e6ac1fcf1623b2c0de6bd6fb415e15012e2e8f56fd9bf8ec1a552b5b15e528048ea8d9f6f5bce0b16f491941b20dd91a9d246459f4c397f891cf175a95806
7
+ data.tar.gz: 6af4e08406d4092107d372f0e8eaa6e5305dff67b9e5db7620151f55fb3b2f7ab3661817187ef4b92fbc85b32d030cd96c33f3c153037683d97fbc2839e7e317
@@ -29,6 +29,7 @@ module TalltyImportExport
29
29
  # json: model_payload,代表存储在某一个列中
30
30
  # select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
31
31
  # source: true,如果source为true,代表从association_record 进行属性查询
32
+ # proc: proc或者lamda,支持call,传入 record 和 context
32
33
 
33
34
  def export_xlsx records, **options
34
35
  records = with_scope records
@@ -174,6 +175,8 @@ module TalltyImportExport
174
175
  try_chain(record, header[:chain])
175
176
  elsif header[:json]
176
177
  record.send(header[:json])[header[:key]]
178
+ elsif header[:proc] && header[:proc].respond_to?(:call)
179
+ header[:proc].call(record)
177
180
  else
178
181
  try_method(record, header[:key])
179
182
  end
@@ -16,6 +16,7 @@ module TalltyImportExport
16
16
  # primary_key: 是否是主键
17
17
  # json: model_payload,代表存储在某一个列中
18
18
  # finder: 执行代码,可以查找到相关的对象
19
+ # proc: proc或者lamda,支持call,传入 val 和 context
19
20
 
20
21
  # xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
21
22
  def import_xlsx xlsx_file, associations, **options
@@ -55,6 +56,7 @@ module TalltyImportExport
55
56
  @headers = options.delete(:headers) || import_headers
56
57
  @primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
57
58
  @params = options
59
+ context.params = @params
58
60
 
59
61
  @excel_hash = @headers.reduce({}) do |h, header|
60
62
  h[header[:key].to_sym] = header[:name]
@@ -67,6 +69,7 @@ module TalltyImportExport
67
69
  def process_line_info line_info, associations
68
70
  # 去除空行内容
69
71
  return unless line_info.values.any?(&:present?)
72
+ context.line_info = line_info
70
73
  # 转换处理导入的数据格式
71
74
  line_info = convert_data(line_info)
72
75
 
@@ -88,6 +91,8 @@ module TalltyImportExport
88
91
  if header[:json]
89
92
  h[header[:json]] ||= {}
90
93
  h[header[:json]][k] = val
94
+ elsif header[:proc] && header[:proc].respond_to?(:call)
95
+ h[k.to_sym] = header[:proc].call(val, context)
91
96
  elsif header[:finder]
92
97
  # $SAFE = 2
93
98
  h[k.to_sym] = eval header[:finder]
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.28"
2
+ VERSION = "1.0.29"
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.28
4
+ version: 1.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - liyijie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-08 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip