tallty_import_export 1.0.15 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06f862bf1ae912a77b1e7a02d76fade118619343de44cbcff2b5f165756ea323
4
- data.tar.gz: db83a7345b10d91e5018604ed08c24287e085930c96b7af66499d6333464f063
3
+ metadata.gz: b1cb38513ee9efd2e26a8cabc623e52306cf5f2a3ecf53711993aeb8067b2915
4
+ data.tar.gz: bcc91bcc85017141640c259777996e2036347fc68a978403d22a7085c704c1b1
5
5
  SHA512:
6
- metadata.gz: ba25061c42d32c4396cbb88b9aae8ef7296b58a306c47037dd5c53cea9bde0d8df29f7ed373463d7f74596f78e73fecf3005aa02a2b449ab9d60f0313631bc63
7
- data.tar.gz: 240105d66e1c3a009fb8f03b70a19cbb0307c3bbe2e611958e7cd019d332404bae5c75b681488595988996f2bc616aa4e445cc73f6bda6389b4ed55eb81e95ee
6
+ metadata.gz: 6465b690fba9935d30109b3423119cc9a93dd6b5872eacc647404400ed50da95156fbb9d1b35d94c7f733fef2236601de11ce244ab76618789ed2756027fe23b
7
+ data.tar.gz: 326fe9117444b0cb0461731181ac2131584b36b64582c8b2a21fab3eb7de761bf27c23d3d710ef703eded66f76fb106373628552437bf042d4371178448c3eb8
@@ -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
 
@@ -75,7 +79,7 @@ module TalltyImportExport
75
79
 
76
80
  def convert_data line_info
77
81
  line_info.with_indifferent_access.reduce({}) do |h, (k, v)|
78
- header = @headers.find do |_header|
82
+ header = import_headers_result.find do |_header|
79
83
  _header[:key].to_sym == k.to_sym
80
84
  end
81
85
  # header[:convert] = handle_xxx
@@ -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
@@ -97,7 +104,7 @@ module TalltyImportExport
97
104
  end
98
105
 
99
106
  def import_headers_result
100
- @headers || import_headers
107
+ @headers ||= import_headers
101
108
  end
102
109
 
103
110
  def import_headers **args
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.15"
2
+ VERSION = "1.0.20"
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.15
4
+ version: 1.0.20
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-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip